Including Template from a lower directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cgroup
Forum Newbie
Posts: 13
Joined: Tue Jun 03, 2003 11:51 pm
Location: PA

Including Template from a lower directory

Post by cgroup »

I created a basic template in my root directory which has the design, which I then include into a PHP file that defines the variables and fills in the template. It works fine in the root, but if I include it from a higher directory the template file isn't parsed.

Here is an example of the template that sits at "/template.php":

Code: Select all

<html>
<head>
<?php
echo "<title>".$TMPL&#1111;'title']."</title>";
echo $TMPL&#1111;'METATAGS'];
?>
<link rel=stylesheet href="/stylesheet/main.css" type="text/css">
</head>
<body bgcolor="#cccccc" background="/images/bg_cccccc.JPG" leftmargin="0" rightmargin="0" topmargin="0">
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td background="/images/headerwest1.JPG" height="115" width="100%">
      
    </td>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="10">
  <tr valign="top" align="left">
    <td width="200">
<?php
include "http://".$_SERVER&#1111;'HTTP_HOST']."/fopolinks.php";

include "http://".$_SERVER&#1111;'HTTP_HOST']."/".$TMPL&#1111;'direction']."/".$TMPL&#1111;'direction'].".php";

if ($TMPL&#1111;'subcategory']) &#123;
echo "<table border="1px" cellpadding="5" cellspacing="0" bordercolor="#000000" width="100%" style="border: solid 2px">
        <tr>
          <td bgcolor="#b0aaa5" style="border: 0px">
            <h3 align="center" style="margin-bottom: 0px">";
echo $TMPL&#1111;'subcategory'];
echo "</h3>
          </td>
        </tr>
      </table>
      <table width="100%" border=0 cellpadding="0" cellspacing="0">";
echo  $TMPL&#1111;'subcategory_links'];
echo "</table>";
&#125;
?>
      <br />
      <table border=1 cellspacing=0 cellpadding=5 align="center">
        <tr align="center">
          <td>
            <h3>Newsletter</h3>
            <p class="small">Enter your email address to recieve updates from FPC!</p>
            <form action="/east/newsletter/tcg_ml_join.php">
            <font size="2"><b>Email:</b></font>&nbsp
            <input type="text" name="email_from" size="15"><br /><br />
            <input class="css" type="submit" value="Subscribe">
            </form>
          </td>
        </tr>
      </table>
    </td>
    <td width=1 bgcolor="#000000">
    </td>
    <td width="*">
    <h1 align="right" style="margin-right: 30px; margin-top: 0px; margin-bottom: 0px"><?php echo $TMPL&#1111;'title']?></h1>
    <h2 align="right" style="margin-right: 30px; margin-top: 0px; margin-bottom: 0px"><?php echo $TMPL&#1111;'subtitle']?></h2>
    
    <hr height="1" color="#000000" NOSHADE>
    
    <?php echo $TMPL&#1111;'content']?>

    </td>
  </tr>
</table>

<hr color="#000000" width="100%" style="margin-left: 10px; margin-right: 10px">

<center>2004 &#169 Four Points Cardinal</center>

</body>
</html>
And this is the main file - that sits at "/ahigherdirectory/file.php":

Code: Select all

<?php

$TMPL&#1111;'METATAGS'] .= <<<EndHTML
<META NAME="DESCRIPTION" CONTENT="Four Points East">
<META NAME="KEYWORDS" CONTENT="keywords, keyword keywords">
<META NAME="OWNER" CONTENT="joshuaditty@cardinal-points.com">
<META NAME="AUTHOR" CONTENT="Four Points Cardinal">
<META HTTP-EQUIV="EXPIRES" CONTENT="">
<META HTTP-EQUIV="CHARSET" CONTENT="ISO-8859-1">
<META HTTP-EQUIV="CONTENT-LANGUAGE" CONTENT="English">
<META HTTP-EQUIV="VW96.OBJECT TYPE" CONTENT="Index">
<META NAME="RATING" CONTENT="General">
<META NAME="ROBOTS" CONTENT="INDEX,FOLLOW">
<META NAME="REVISIT-AFTER" CONTENT="4 days">
EndHTML;

$TMPL&#1111;'content'] .= <<<EndHTML
<img src="/images/cardinal2.JPG" align="left" alt="Four Points Cardinal">
                                        <P>The Cardinal Group is very hard to describe because we promote several fronts.  In the west we have business, where we market affiliate products and provide resources to entrepreneurs.  But we aren't just a business.</P>
                                        <p>In the north we promote charities and organizations that fight a cause, but we aren't a charity, either.  In the south we promote the arts and education, but we aren't a school.</p>
                                        <p>If you want to know what the Cardinal Group is, I guess we're a little of all of these.  Business, charity, and the arts - and here in the East we bring them all together to provide you with up to date information on what TCG is doing.</p>
                                        <h3 align="left">Direction</h3>
<p>TCG is named after the four cardinal directions of North, South, East, and West.  This word has a strong meaning to us.  Direction is an important part of life, and setting goals and priorities is essential.</p>
<p>Here, our goal is simple.  We are determined to develope our business strategy through online marketing in order to gain the capital required to grow and expand in the other directions - business, charity, and the arts.</p>
<p>I'd like to invite you to join us in our journey - all you have to is choose the direction and TCG will be there to lead the way.</p>
EndHTML;

$TMPL&#1111;'title'] .= "Four Points East";
$TMPL&#1111;'subtitle'] .= "Graphical Design";
$TMPL&#1111;'direction'] .= "east";
$TMPL&#1111;'subcategory'] .= "";
$TMPL&#1111;'subcategory_links'] .= <<<EndHTML
        <tr align="left">
          <td>
          </td>
        </tr>
EndHTML;

require_once ('http://fopo.net/template.php');
?>
Does anyone know how to make it parse the template file. I could place a copy of the template file in every directory, but that defeats the purpose of a template.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

You are requesting the template via http therefore you will only get the parsed templatefile back.

Using your path example i.e. you are in the next directory in, try requiring it by using a relative path e.g.

Code: Select all

require_once ('../template.php');
cgroup
Forum Newbie
Posts: 13
Joined: Tue Jun 03, 2003 11:51 pm
Location: PA

Post by cgroup »

Ah - WOW. Thank you, it works perfectly. :D
Post Reply