Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question PHP Server side template inclusion

    <?php
    $title = "My Title";
    $text = "I need to have 5 paragraphs of text here.";
    ?>

    <?php include ("template.php"); ?>

    ----------

    I want to use the script above as a file which will work with the template.php file.

    For "$text", I have 5 paragraphs of text, but I don't want to insert it there as a php inclusion from a third file.

    Is there another way to put the text there?

    I just want to get it done with two files.

    Thanks!

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't think I understand what you mean. Where are you getting these 5 paragraphs from? If it's in a separate file then....?

    Sadiq.

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    FIRST:


    I have a template file called template.php.

    I also have a set of files. For the sake of the conversation, we can call them:

    textfile1.php
    textfile2.php
    textfile3.php
    textfile4.php
    textfile5.php

    Each of these text files contain paragraphs of text.

    The template file has $title and $text that needs to be filled in by these textfiles.

    -------

    SECOND

    Since these textfiles should embed the necessary text in the template.php file, a typical textfile.php would be like:

    <?php
    $title = "My Title";
    $text = "I need to have 5 paragraphs of text here.";
    ?>
    <?php include ("template.php"); ?>

    ---------

    QUESTION:

    As you see, I have no problem with the title. I just write it there, and that's it.

    But as for the 5 paragraphs, I don't know what to do.

    I know a solution though. For $text, I can make php inclusions from .html files which would have just:

    <p>a paragraph of text</p>
    <p>a paragraph of text</p>
    <p>a paragraph of text</p>
    <p>a paragraph of text</p>
    <p>a paragraph of text</p>

    But I don't want to do that. Because I want to get this done with only two files: 1.template.php 2.textfile1.php

    Therefore I need to know how I can put 5 paragraphs of text for $text without the obligation of a third file.

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok so textfile.php will hold the title, a variable $text, and include template.php.

    i'm still not sure where the 5 paragraphs are coming from. are they coming from eacho of textfileX.php? so textfile1.php is paragraph 1, ...?

    because if that's the case, i'm confused as to how you're planning on doing that, as each textfileX.php includes template.php....

    so i need more specifications.
    sadiq.

  • #5
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    dear sadiq, (loyal, that is, right?)

    you are talking about the exact same problem.

    these 5 paragraphs are not in any of the files. actually, this is what the problem is.

    we are trying to find a way to somehow equalize them to $text.

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In arabic, as far as I know, Sadiq == Honest. But loyal could be right too..

    In regard to your problem, I see that you're not sure where the paragraphs are coming from either.

    In order to figure out where you want to put these 5 paragraphs, you should ask/answer the following questions:
    -why do you need the different textfile.php?
    -will the 5 paragraphs differ in each of the textfile.php?
    -are there other php files that will include template.php which will have a different 5 paragraphs?

    The point I'm trying to make here is will these 5 paragraphs be the same for all pages? Such that if the 5 paragraphs were to change in on file, should they change in all files?

    Possible places could be to place them in template.php (the 5 paragraphs should be the same on all pages), in a separate file (which you seem to be against... why, if I may ask? This would be the easiest place to keep them for updating, etc.. that is if the 5 paragraphs should be the same on all pages), in a database record (same idea as a file really..), or retype them in each textfile.php (if each textfile.php should have a different 5 paragraphs).

    There may be some other places, but I can't think of them right now...

    Hope that helps,
    Sadiq.

  • #7
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I understand.

    The textfiles are all different.

    The template.php will be a template file for about 60 files. 60 textfile.php files in other words. Some will have 3 paragraphs some 10.

    I don't want to have them separately because otherwise I will have three files to execute each single page, and it will be difficult to update because of the nature of the file.

    I want to execute each page with two files: template.php (which has all the style, tables etc.) and the textfile (which has the text, and instructions as to where to include them)

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Seeing as the "paragraph" portion will not be static, and will be changing for each textfile.php, then you should actually include the "paragraphs" in each textfile.php.

    If you have certain "paragraphs" that will be repeated in some/many textfile.php, then I would suggest putting these paragraphs as records in a database, then you could select the appropriate paragraph message to place in the textfileX.php file as necessary...

    Unless I'm missing something, that's what I'd do. Let me know what you decide, or if you still can't make up your mind and why.

    Sadiq.

  • #9
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sadiq,

    Please visit:

    http://www.fiscalstudy.com/template.txt (the script)

    http://www.fiscalstudy.com/template.php (the page)


    I put all the details there for you.

    Thanks!
    Last edited by ssskaya; 03-30-2004 at 11:23 PM.

  • #10
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whew, this took a little thought, but the solution is quite simple -- I think so at least.

    I hope this works for you:

    So you have the template.php. If you want to open a page, lets say contacts.php, what you should do is this:
    Have your source code for the contacts page (just the table, text, and images...) in contacts.php. contacts.php should not hold any includes for header, footer, etc...

    How you would open contacts.php is as follows:
    template.php?page=contacts.php

    Now in your template.php where you want the contacts.php page to show up, you include $page, where $page == "contacts.php".

    Does that make sense?

    You'd have to change your menu so that instead of opening contacts.php, it will open template.php?page=contacts.php, and all the links in your website accordingly, but that's the cleanest way to go about this I think. And this way you only have 1 template file, and then 1 file for each of your webpages.

    I've attached a couple files, hopefully it helps you understand better. I think my explanation was sort of crappy... let me know if you're still stuck.

    Good luck,
    Sadiq.
    Attached Files Attached Files

  • #11
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sadiq:

    Yes I understood what you said. Although I never dod that before, no worries, it was quite clear.

    I will let you know what happens.

    And I would be damned if I don't say this: This was the greatest help I ever got in a forum - since this thing was very important to me. You must have understood that when you saw my site.

    Thanks for spending time on it.

    I say they should make you a MODERATOR or something.

    you are not just a "CF Regular" like me!

  • #12
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey no problem! Lol, I already have a fulltime job, but I'm flattered anyway!

    But lookie, I'm a CF Addict now! Sweeet! lol

    Good luck with it, and let me know if you have any troubles (I doubt you will..).
    Sadiq.

  • #13
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I tried the attachment on the server but it shows blank.

    For $page I uploaded the page1.php that you attached. On the browser's address bar I wrote: ....com/template2.php?page=page1.php

    did I do something wrong or is there something wrong with the inserted php script?


    PS: That's because I renamed it to template2.php (it's still there)
    PSS: The page looks fine when I exclude the php script that you inserted. A copy of it is below.



    <?php
    if(in_array("page", $_GET)) {
    $page = $_GET["page"];
    if ( file_exists($page) ) AND !preg_match("#^\.\./#",$page) ) {
    include $page;
    }
    else {
    echo "Invalid page requested.";
    }
    }
    else { //no page included
    echo "Please request a page.";
    }
    ?>
    Last edited by ssskaya; 04-01-2004 at 01:12 AM.

  • #14
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whoops! I think this may be the problem at least...

    Change:
    include $page;

    to:
    echo include $page;

    I think that should fix it... let me know.

    Sadiq.

  • #15
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    sorry.

    still blank..


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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