Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
PHPTAL styled macros?

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
asmodeus
Smarty n00b


Joined: 23 Mar 2010
Posts: 1

PostPosted: Tue Mar 23, 2010 5:12 pm    Post subject: PHPTAL styled macros? Reply with quote

Hi guys,

I am in serious need of assistence here. I have just started a new web development job and the new boss is a big fan of the PHPTAL template parser. Personally I dont aggree and really want to convince him that we should be using smarty. His main argument for PHPTAL so far has been its use of macros (which I admit is kind of nifty), but if can replicate the same functionality in smarty then I can probably convince him. This is where I need some help...

PHPTal allows you to do things like...

Code:
<div metal:define-macro="box" tal:attributes="class class; id id">
   <h1><tal:block metal:define-slot="heading"/></h1>
   <p><tal:block metal:define-slot="content" /></p>
</div>


and then use this code later by doing...

Code:
<tal:block metal:use-macro="box" tal:define="class string:bloxclass; id string:boxid">
   <tal:block metal:fill-slot="heading">
      Header Hoes Here
   </tal:block>
   <tal:block metal:fill-slot="content">
      <p>This is the body content of the webpage</p>
      <img src="image.jpg"/>
      <a href="next.html">Click Here To See More</a>
   </tal:block>
</tal:block>


So, what I would like to be able to do is...

Code:
{define-macro name="box"}
<div class="{$class}" id="{$id}">
   <h1>{$heading}</h1>
   <p>{$content}</p>
</div>
{/define_macro}


and use it, something similar to...

Code:
{use_macro name="box" class="bloxclass" id="boxid"}
   {macro_assign name="heading"}
      Header Hoes Here
   {/macro_assign}
   {macro_assign name="content"}
      <p>This is the body content of the webpage</p>
      <img src="image.jpg"/>
      <a href="next.html">Click Here To See More</a>
   {/macro_assign}
{/use_macro}


But I cant quite figure it out...

Can anyone help?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4176
Location: Hamburg / Germany

PostPosted: Tue Mar 23, 2010 6:59 pm    Post subject: Reply with quote

Smarty3 does have some new features like the {function} tag for template functions or template inheritance which might be of use.

Check the README at http://smarty-php.googlecode.com/svn/branches/Smarty3Dev/distribution/README for further details.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP