php in a template
Archived from the Xataface Users forum.
wisni1rr — Wed Apr 18, 2012 12:14 pm
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!
shannah — Wed Apr 18, 2012 1:02 pm
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"; }
- The discouraged approach:
Use the Smarty {php} {/php} tags in your template.
http://www.smarty.net/docsv2/en/languag … on.php.tpl
-Steve
wisni1rr — Thu Apr 19, 2012 10:11 am
Thanks Steve! The first approach is exactly what I was looking for!