I want php in my .tpl, I think

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
DB
Regular
Posts: 22
Joined: Mon May 01, 2006 9:40 pm
Contact:

I want php in my .tpl, I think

Post 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
DB
Regular
Posts: 22
Joined: Mon May 01, 2006 9:40 pm
Contact:

Another method, but doesn't work

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Another method, but doesn't work

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
DB
Regular
Posts: 22
Joined: Mon May 01, 2006 9:40 pm
Contact:

No Comm

Post 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.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: No Comm

Post 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:

Code: Select all

<?php
die('CONFIG LOADED!');
?>
If your s9y blog then stops working, the config.inc.php is parsed.

Else try to write this in your index.tpl:

Code: Select all

Ref: {$ref}
just to see if the variable is used/shown.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
DB
Regular
Posts: 22
Joined: Mon May 01, 2006 9:40 pm
Contact:

Still Nothing

Post 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).

Code: Select all

<?php 
die('CONFIG LOADED!'); 
?> 
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.

Code: Select all

Ref: {$ref}


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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Still Nothing

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
DB
Regular
Posts: 22
Joined: Mon May 01, 2006 9:40 pm
Contact:

It Works!

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: It Works!

Post by garvinhicking »

Hi!

Didn't mean to kick you. :-))

I hope you'll continue to have fun with Serendipity!

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply