Page 1 of 1

php in a template

PostPosted: Wed Apr 18, 2012 12:14 pm
by wisni1rr
I was wondering if I could include php somehow into a template.

I have a template that I am using as a dashboard/landing when people log into my application. I would like to add php to my template so I can determine the logged in users role and display different content based on the role.

Code: Select all
{use_macro file="Dataface_Main_Template.html"}
    {fill_slot name="main_column"}
PHP HERE
    {/fill_slot}
{/use_macro}


Thanks for help in advance!

Re: php in a template

PostPosted: Wed Apr 18, 2012 1:02 pm
by shannah
Disclaimer: Style-wise this is frowned upon as templates are meant to provide a separation of the view from the code.


However, the answer is yes.

The first approach (recommended): Use block to embed content you implement inside a delegate class.

e.g.
Code: Select all
{use_macro file="Dataface_Main_Template.html"}
    {fill_slot name="main_column"}
         {block name="my_special_block"}
    {/fill_slot}
{/use_macro}


Then in your delegate class, you would implement the block:
Code: Select all
function block__my_special_block(){
     echo "This was output from PHP";
}



2. The discouraged approach:

Use the Smarty {php} {/php} tags in your template.
http://www.smarty.net/docsv2/en/languag ... on.php.tpl

-Steve

Re: php in a template

PostPosted: Thu Apr 19, 2012 10:11 am
by wisni1rr
Thanks Steve! The first approach is exactly what I was looking for!