Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PEAR Integrated Templates

Status
Not open for further replies.

Knackers

Technical User
Apr 26, 2001
59
0
0
AU
Hi - I am using PEAR IT and it all seems pretty straight forward. However, i am tryign to assign a place holder dymanically by using the <!--INCLUDE --> statement, and it doesn't seem to work for me. Basically I am grabbing a page name from $HTTP_GET_VARS[] and then trying to set it to a variable, then in the tpl file trying to dynamically include the page requested (basically the same as an include statement)

Code:
$template = new HTML_Template_IT('.');
$template->loadTemplatefile(&quot;content.tpl&quot;, true, true);
   
   
/* Check to see which page has been requested and if the file exists. If not, include error message */
			      
if(!empty($HTTP_GET_VARS[page])&& file_exists(&quot;content/$HTTP_GET_VARS[page].tpl&quot;)) 
   {
      $page=&quot;content/$HTTP_GET_VARS[page].tpl&quot;;
   } 
   else
   {
      $page=&quot;content/error.tpl&quot;; 
   } 
	
$template->setCurrentBlock(&quot;CONTENT&quot;);
$template->setVariable(&quot;PAGE&quot;, $page);
$template->parseCurrentBlock();
$template->show();

Then in the template (.tpl) file, I assign the 'PAGE&quot; variable to a placeholder like this:

Code:
<!-- INCLUDE {PAGE} -->

This doesn't seem to work - however if I hard code the path to the file in the indclude statement (Ie: <!-- INCLUDE content/test.tpl --> it works no problem?

If anyone has any idea on why this doesn't work - I'd love to hear about .

CHeers
 
Not sure, but don't you need the $?


if(!empty($http_GET_VARS[$page])&& file_exists(&quot;content/$http_GET_VARS[$page].tpl&quot;))
{
$page=&quot;content/$http_GET_VARS[$page].tpl&quot;;
}
else

tgus

____________________________
Families can be together forever...
 
Thanks tgus.
You don't need the $ sign because I am just grabbing the variable value from the GET associative array

eg
Echoing out the value of $page and indeed the {PAGE} placeholder confirms that the variables are being passed and set.

The problem, it would seem lies within the dynamic inclusion of the page file at the line:
Code:
<!-- INCLUDE {PAGE} -->

Everything else works as it should. As I said, when I hard code the value into the <!--INCLUDE page1.php --> it works perfectly. But not using the above dynamic approach.

Unfortunately, my time for working this out is getting short, so i may just have to go back to mix my php with HTML and just use dynamic &quot;include()&quot; statements instead. That would be a real shame because I reckon the PEAR stuff is really good and I would really like to make use of it. I am sure what I am trying to do can be done.... just don't know how.
 
Have you checked for case sensitivity?

Or the path to the INCLUDE()d file?


tgus

____________________________
Families can be together forever...
 
Here's an example I've seen in a working script;

include(&quot;./car.php4&quot;);

HTH!


tgus

____________________________
Families can be together forever...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top