php in a template

A place for users and developers of the Xataface to discuss and receive support.

php in a template

Postby 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!
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm

Re: php in a template

Postby 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";
}



2. The discouraged approach:

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

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: php in a template

Postby wisni1rr » Thu Apr 19, 2012 10:11 am

Thanks Steve! The first approach is exactly what I was looking for!
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 12 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved