Hello everyone. I have a site that is in php and I'm using this code- <div>{include file="test.tpl"}</div> to add stuff in the page. I was wondering if there was a way to only add this to the index page? When I add it to the layout.tpl file it's on every page and I only want it on the index page. I would appreciate any help. Thanks in advance.
try this.. {if $_SERVER[SCRIPT_NAME] == "/index.php"} <div>{include file="test.tpl"}</div> {/if} Code (markup):
The issue isn't in your code or php but that you're using some kind of template system to build multiple pages. You can leave that out of your template and use a regular php 'include' statement in your finished index page, something like: <? include ("test.php");?> (I suspect a ".tpl" file is some sort of template rather than an html or php file?)
For the above, did you even read the OP? Anyway, that wouldn't work in the situation where assumed, something like this would: if(strpos($_SERVER['PHP_SELF'], 'index.php') == true){ include('test.tpl'); } Code (markup):
Thank you all for your help. I have tried everyone's info and none have worked so far. Chopsticks, would that code go in between the divide tags? And in that code it uses- 'test.tpl' - Should it be "test.tpl" with the quotation marks instead?
I assume you are using Smarty? Looking at the second reply you can change it to be this instead. I'm not to sure how everything actually works in Smarty and prefer not using it, lol. {if $_SERVER['PHP_SELF'] == "/index.php"} <div>{include file="test.tpl"}</div> {/if} Code (markup):
I'm not sure what I'm using. The site is a script I purchased from somebody. I tried the code that way and still no luck.
Go to the library where your template parser is and check the headers of the file. If docummented they should state the name of the template parser that you are using.