Forum Moderators: coopster

Message Too Old, No Replies

Smarty Templates + PHP (need help)

         

dekay

2:59 pm on Apr 25, 2007 (gmt 0)

10+ Year Member



Need some help with the syntax. For example, if this is my tpl file:

<html>
{$sample}
</html>

And this is my php file:
$s->assign("sample","This is where I want to insert php code");

How do I put php scripts inside the bolded area?

joelgreen

7:44 pm on Apr 25, 2007 (gmt 0)

10+ Year Member



Maybe this will help
[smarty.php.net...]

dekay

9:56 pm on Apr 25, 2007 (gmt 0)

10+ Year Member



That's what I'm currently using but is not the solution I'm looking for. Using that method means I have to maintain multiple templates if each page has a different php script in it.

For example, assume that my template includes only a header and footer with a content cell in the middle. I'm looking for a solution for a multi-page site, where I can create files by calling one template. Therefore, I need to know how to include php code in the php file (which is calling the template) and not hard coded into the template itself.

Can it be done in Smarty?

joelgreen

10:35 am on Apr 26, 2007 (gmt 0)

10+ Year Member



Include header/footer into each separate "content" page.

mypage1.tpl
------------
{include file="header.tpl"}
Here is my page 1 text.
Here is my page 1 text.
{include file="footer.tpl"}

mypage2.tpl
------------
{include file="header.tpl"}
Here is my page 2 text.
Here is my page 2 text.
{include file="footer.tpl"}

and in your php file where you initialize Smarty

switch($page_id) {
case 'page1':
$smarty->display("mypage1.tpl");
break;
case 'page2':
$smarty->display("mypage2.tpl");
break;
}