Page 1 of 1
I want php in my .tpl, I think
Posted: Sat Jun 03, 2006 2:27 am
by DB
Hello,
I'm trying to call up one of two menus from my index.tpl using smarty and php. The chosen menu will depend upon which page the user is linking from. Is this possible? I know I can't put the php directly into the tpl, so here is the code I am currently using which isn't doing what I want.
config.inc.php
Code: Select all
<?php
$serendipity['smarty']->assign('ref', $_SERVER['HTTP_REFERER']);
?>
index.tpl
Code: Select all
{if $ref == 'http://www.FIRST OF THREE ADDRESSES.html'}
{if $ref == 'http://www.SECOND OF THREE ADDRESSES.html'}
{if $ref == 'http://www.THIRD OF THREE ADDRESSES.html'}
//menu if the user is coming from 1 of 3 addresses
{else}
//menu for someone coming from anywhere else
{/if}
What I would like to do is have the code discover if the user is linking to the page from 1 of 3 different pages. The user will only have access to the page from any of those 3 pages. So when the user comes to my page with the index.tpl, it will pop up the correct menu. If it is not from 1 of the 3 pages, it will run the {else} menu.
Sorry for being confusing. It just seems to be the only way for the time being. Can this be done??? If so how?
Thanks,
Dan
Another method, but doesn't work
Posted: Sat Jun 03, 2006 3:17 pm
by DB
Also...
I tried using the method that is described at
http://www.s9y.org/78.html under the subtitle "Inserting you own Stuff", but that does not seem to be working either. I made a php file called config.inc.php that holds the php I want. The file lives in the same directory as the index.tpl file. Then I am using Smarty's method of calling up a file which is:
Code: Select all
{include_php file="config.inc.php"}
When I do this I get an error message that says the file is not readable from the Smarty.class.php on line 1088.
What gives??
Thanks for any help
Dan
Re: Another method, but doesn't work
Posted: Sun Jun 04, 2006 12:10 am
by garvinhicking
Hi!
Actually the way you described in your first posting would be right. You just need to use the right Smarty syntax:
Code: Select all
{if $ref == 'http://www.FIRST OF THREE ADDRESSES.html' OR
$ref == 'http://www.SECOND OF THREE ADDRESSES.html' OR
$ref == 'http://www.THIRD OF THREE ADDRESSES.html'}
...
{/if}
Your way of IF nesting would need also three {/if} closing statements.
PHP includes in Smarty are by default not enabled. Which is why in the documentation we refer to the template'S config.inc.php where you need to put wrapping code. But you shouldn't be needing this specific method, because your described way should work fine.
Best regards,
Garvin
No Comm
Posted: Sun Jun 04, 2006 2:10 am
by DB
Thank you so much for the reply,
I'm still not getting any communication going on between the config.inc.php and the index.tpl.
The file that I am putting the Smarty markup in is /templates/default/index.tpl.
Now where exactly do I put the config.inc.php file?
From what documentation I read, the file needs to be created and then put into the same directory as the tpl. Is this correct? I used the same php as in my first post to go into my config.inc.php file.
Just not getting a response like I should with that setup.
Re: No Comm
Posted: Sun Jun 04, 2006 2:30 pm
by garvinhicking
Hi!
The config.inc.php needs to be in the same path as your index.tpl file is in!
Try to create this in your config.inc.php:
If your s9y blog then stops working, the config.inc.php is parsed.
Else try to write this in your index.tpl:
just to see if the variable is used/shown.
Regards,
Garvin
Still Nothing
Posted: Sun Jun 04, 2006 3:07 pm
by DB
Hello,
Thanks for your continued help! I put the following code in my config.inc.php and it is appently not being read, because it didn't make any change in the blog (still loaded fine).
The file is also in the place you indicated, along with the index.tpl. Also the following code just pulled up "Ref:" on the page with no address.
Why is this happening? Is there anywhere else I could place the Php to communicate with the tpl?
Also, My theme is set to s9Y Orange. That is where I make adjustments to my CSS. Then I am altering the default theme index.tpl, that is where the config.inc.php file resides. I have tried putting it in my s9Y Orange theme file, and that doesn't do anything either. Is this setup somehow causeing the file not to be parsed?
Thanks again for your help!
Dan
Re: Still Nothing
Posted: Sun Jun 04, 2006 3:18 pm
by garvinhicking
Hi!
You didn't mention you weren't using the default theme. *g*
So, I guess I need to be more precise: The config.inc.php needs to be within the template directory of the template you are using.
If a .tpl file is not contained iny our active template directory, it is fetched frm the "default" directory - but the config.inc.php is always searched in your active template directory only.
If you are altering a .tpl file, NEVER alter it in the default directory. Always copy it over into the theme directory of the theme you are modifying, that's safer.
(Some clarifications are in the templating section of s9y.org...)
HTH,
Garvin
It Works!
Posted: Sun Jun 04, 2006 3:30 pm
by DB
Thanks for the kick in the pants
I remember reading about that during my first Serendipity install. In fact, I even altered my theme tpl's in that fashion. Then I got so many different Serendipity experiments going on...I figured I'd just as well adjust the default, not spending any extra time moving the files around. Then if I found that I needed my original default.tpl back, I would just pull it out of another serendipty folder.
I LEARNED MY LESSON
It's working great now, just as expected. Thanks again for the help, I really appreciate it.
Dan
Re: It Works!
Posted: Sun Jun 04, 2006 4:13 pm
by garvinhicking
Hi!
Didn't mean to kick you.

)
I hope you'll continue to have fun with Serendipity!
Best regards,
Garvin