• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

php dynamic page title

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    php dynamic page title

    Hi,
    I was wondering if there are any web master members who know a way to solve a issue I'm having with a php / ruby run web site.

    I am putting a site together that uses a common php include header. This of course then presents a common page title which I need to solve for SOE reasons. The way the header works also includes the navigation and the top of each page with the <body> tag. The other issue is that the header is a rhtml file as the back end runs on ruby, which I can not change or access (aside from the templates). This means it has a low tolerance for including too much php scripting before breaking it.

    I have search the web for ways around this and found a few near but not quite there answers. A lot revolve around the naming the <body> with a class, which I can not use.

    I'm looking for a way that can pick up another element in the individual page. I have found this method which uses a heading class to work (Although I'd change it to use a <h2 = class"">):

    <?php if ($title): ?>
    <?php print render($title_prefix); ?>
    <h1 class="title" id="page-title"><?php print $title; ?></h1>
    <?php print render($title_suffix); ?>
    <?php endif; ?>

    I can't get this to work though. The anonymous source on a pastebox site was unclear on any detailed usage instruction. I am not sure on what to place in the header and what to place on the page. When placed in the header it just breaks the script as expected. Has anyone else had this sort of problem and found a fix please? Or can make more sense out of this code than me.

    Kind regards
    kipper

    #2
    No Ruby on this example but this is how I have it working on a pure PHP site which pulls a common header:

    At the top of the individual page page where you want to specify a unique page title:

    Code:
    <?php
    $_TITLE = "This is the page specific title";
    
    require_once("headerhome.template.php");
    ?>

    Then in the header template:

    Code:
    <?php
    if (!$_TITLE) {
      $_TITLE = "This is the generic page title.";
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
     <title><?=$_TITLE?></title>

    Comment


      #3
      Thanks for that. It looks like a perfect working solution. My only concern is that any php above the doc type seem to break the ruby header, it is a bit unforgiving like that; but I will give it a go and see.

      regards

      Comment


        #4
        SOLVED

        Admin - You are my Hero(in)
        Topic Solved - It WORKED!! I've been battling with this one for the better part of two weeks (well not continuously).

        Many many thanks - Contractor UK Rocks.

        Kipper

        Comment


          #5
          Damn it!

          FFS!!!
          Spoke a bit too soon there. Works a total treat on the php generated pages but the ruby generated pages the title is printed as <?=$_TITLE?> This includes the home page.

          To be expected I guess, not sure that ruby can read php?

          Seems this is one battle I can not win. makes me...

          As a crappy work around I may go with a generic title followed by the php <?=$_TITLE?>
          This will print the code at the end of the header title in the ruby pages only which isn't great but I can use it while I find an alternative as this is holding up publication now.

          Thanks for your coding help; cures about 75% of the problem at least.

          Comment


            #6
            Originally posted by Kipper View Post
            FFS!!!
            Spoke a bit too soon there. Works a total treat on the php generated pages but the ruby generated pages the title is printed as <?=$_TITLE?> This includes the home page.

            To be expected I guess, not sure that ruby can read php?

            Seems this is one battle I can not win. makes me...

            As a crappy work around I may go with a generic title followed by the php <?=$_TITLE?>
            This will print the code at the end of the header title in the ruby pages only which isn't great but I can use it while I find an alternative as this is holding up publication now.

            Thanks for your coding help; cures about 75% of the problem at least.
            If the server (presumably Apache) is configured to serve .rhtml files via the appropriate Ruby module, then the PHP module (mod_php or whatever) will never see them, and thus never get a chance to run any PHP code in them.

            Comment


              #7
              Thanks Nick
              I sort of figured as much. But it is nice to have it confirmed, that way I know that my search for a php answer is fruitless.

              Maybe time to start learning some rails! Never, managed to get my head around the first tutorials I saw when I first looked though!

              Comment


                #8
                Originally posted by Kipper View Post
                Thanks Nick
                I sort of figured as much. But it is nice to have it confirmed, that way I know that my search for a php answer is fruitless.

                Maybe time to start learning some rails! Never, managed to get my head around the first tutorials I saw when I first looked though!
                It's worth persevering with Rails - it's a great framework.
                "A life, Jimmy, you know what that is? It’s the s*** that happens while you’re waiting for moments that never come." -- Lester Freamon

                Comment


                  #9
                  My Solution

                  Thanks for all the posts and help.
                  Having duelled on this for a few days I have decided the only answer in this case is to run twin header idents. One for the ruby set up and one for the php files. Not a perfect solution but its only an extra file to copy update as and when it is required.

                  cheers

                  Comment


                    #10
                    Originally posted by Kipper View Post
                    Not a perfect solution but its only an extra file to copy update as and when it is required.
                    And of course your build-and-deploy process will automate that

                    Comment

                    Working...
                    X