SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict Chillijam's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using auto_prepend_file

    Hi,

    I am using the auto_prepend_file functionality of PHP to show the page furniture of my site. Basically, the prepend file sets up the page, right down to starting the <div> that will display the content, including the title for the page. It also includes a few function definitions.

    Can anyone confirm for me that the only way to set the title in such a page would be a chunk of JS in the content page, or is there actually another way that I am not aware of?

    Sample code...

    prepend.php

    PHP Code:
    <html>
    <head>
    <title>Static Title</title>
    </head>
    <body>
    <div class="content">
    <?php 
    require_once "requiredfile.php";
    function 
    myfunct(){
        
    //do something...;
    }
    ?>
    append.php

    PHP Code:
    </div>
    </
    body>
    </
    html
    index.php

    PHP Code:
    // auto_prepend_file calls in prepend.php
    This is a piece of text that will display in the "content" div.
    // auto_append_file calls in append.php 
    Your mind is like a parachute. It works best when open.
    (HH The Dalai Lama)

  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php manual
    auto_prepend_file string

    Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the include() function, so include_path is used.
    I would say no. Because the file is parsed before the main file then you can not pass data to the prepended file.

    Unless you dont have the prepended file output the html directly. If you store the "furniture" in a variable in the prepended file then in the main file you could do a replacement in that string for the title before outputting. You would still automatically have your sites look and feel included in every page but you would have some control over it then. That may work for you.
    Erh

  3. #3
    SitePoint Addict Chillijam's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have just had a flash of the obvious, and added the following solution, which uses Javascript.

    prepend.php

    PHP Code:
    <html>
    <head>
    <title>Static Title</title>
    </head>
    <body>
    <div class="content">
    <?php
    require_once "requiredfile.php";
    function 
    myfunct(){
        
    //do something...;
    }
    // added this function.....
    function pagetitle($newtitle){
      echo 
    "<script language=javascript>document.title = \"$newtitle\";</SCRIPT>";    
    }

    ?>
    This means that the default title is "Static Text", but if I call the function from my main page, the JS will be output to change the title.

    index.php

    PHP Code:
    // auto_prepend_file calls in prepend.php
    <?php 
    pagetitle
    ("Dynamic Title");
    ?>
    This is a piece of text that will display in the "content" div.
    // auto_append_file calls in append.php
    That takes the heat out of my problem. If there is a soluition (which I agree with Mandibal on - there probably isn't) I now have time to think it through more betterer.
    Your mind is like a parachute. It works best when open.
    (HH The Dalai Lama)

  4. #4
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This really isn't acceptable because you dump the dynamic part of the website on to the client which may not execute the JS code. Maybe someting different like
    PHP Code:
    // index.php
    display_header('My Test Page'); 
    would be better where the function display_header is defined (or included) in your auto_prepend file and encapsulates your header markup and provides a dynamic title with the function parameter.

  5. #5
    SitePoint Addict Chillijam's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gaheris
    This really isn't acceptable because you dump the dynamic part of the website on to the client which may not execute the JS code. Maybe someting different like
    PHP Code:
    // index.php
    display_header('My Test Page'); 
    would be better where the function display_header is defined (or included) in your auto_prepend file and encapsulates your header markup and provides a dynamic title with the function parameter.
    You know, there are good points about SitePoint, and there are bad points. I haven't yet been able to decide whether being given an obvious (and correct) answer like this is good or bad, from a personal point of view. I mean, I have my self-respect to think of, you know*!!!

    Thanks Gaheris.


    *actually, I dont. I put that in a small box on a high shelf long ago, along with my hopes of becoming an astronaut.
    Your mind is like a parachute. It works best when open.
    (HH The Dalai Lama)

  6. #6
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry if my post was in any kind aggressive, it was not ment to be. Please blame it on my poor english which is is not my mother tongue.

  7. #7
    SitePoint Addict Chillijam's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gaheris
    I'm sorry if my post was in any kind aggressive, it was not ment to be. Please blame it on my poor english which is is not my mother tongue.
    Not at all Garehis. It was not taken as aggressive in any way. I was just saying that sometimes it takes another pair of eyes (in this case, you) to see the blindingly obvious.

    I wasn't in any way offended or upset by your post. Quite the opposite.

    Thank you once again.
    Your mind is like a parachute. It works best when open.
    (HH The Dalai Lama)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •