use php in template? Topic is solved

General project discussion. NOT for help questions.
Post Reply
angels

use php in template?

Post by angels »

how can i use php in the template?
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: use php in template?

Post by nils73 »

usually you can use php in smarty by using {php} echo "Hello World"; {/php} ... but as Patricia already pointed out, User Tags are much better here.

Regards,
Nils
dan

use php in template?

Post by dan »

i'm trying to print the variable name to the template each time a user passes the name through a url string--to display a diifferent header image for each page. i've created a user friendly tag called {graphic_header} and placed it into the template. the php code i'm using is this (without tags. problem is, the variable name isn't printing to the page. any suggestions/help would be appreciated. thanks!

echo "$page";
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: use php in template?

Post by nils73 »

I use this one on my pages:

global $gCms;
$thispage = '';
$thispage = $gCms->variables['page_name'];

Simply put this into your user-defined tag and it should work ...

Regards,
Nils
dan

Re: use php in template?

Post by dan »

pardon my stupidity. i pasted your code into my userdef tag. do i change [page_name] to something else. in my case $thispage is $page. doesnt seem to work. thanks anyway.
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: use php in template?

Post by nils73 »

I am not quite sure whether $page is already taken by CMSMS ... I just created a user-defined tag called "labelme" and inserted the following code:

Code: Select all

global $gCms;
$thispage = '';
$thispage = $gCms->variables['page_name'];

echo $thispage;
Then you simply insert the following code (just for testing) into your template(s) body-element:

Code: Select all

<p>My page_name is: {labelme}</p>
If you now open any webpage, it should work. At least it does on my installation of CMSMS - tested only a few minutes ago. Good luck.

Regards,
Nils
dan

Re: use php in template?

Post by dan »

that worked. thanks Nils!!!!
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: use php in template?

Post by nils73 »

Glad to hear that, dan. Good luck!
Post Reply

Return to “General Discussion”