Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

convert from fasttemplates question

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
monotreme
Smarty Regular


Joined: 22 Feb 2004
Posts: 97
Location: USA

PostPosted: Fri Feb 27, 2004 12:05 am    Post subject: convert from fasttemplates question Reply with quote

I have a lot of experience with fasttemplates but I am writing my next big project in smarty
because I like the idea of design logic vs. business logic and I think I can play with cacheing to get faster results (even though there is a caching version of fasttemplates now)

In fast templates I use 1 template variable/ page with placeholders that may be replaced with other templates or just stuff that you calculate. At the beginning, you take all the placeholders that are files and tell it about them. So now all the placeholders in any subtemplates, plus any stuff that you didn't assign a template to becomes assignable. Then at the end you parse each subtemplate into the main one.

Smarty doesnt seem to have this parse phase. You just seem to need to assign values into all the placeholders and then display the template. This works fine but I'm just a little fuzzy about how to tell smarty to use a nonstatic subtemplate like header.tpl to put into $header (which would be a smarty var in the main template.) I have made it work by making a new Smarty called $htpl, calculating & assigning all the stuff that should go in the header, then passing $htpl->fetch() back to the main smarty template

So its like this:
Code:

function make_header($whatever) {
   
   $htpl = new mySmarty();
   //calculate some stuff based on $whatever.....
   $htpl->assign(array
         //templ vars =>  stuff I calculted....
   ))
   return $htpl->fetch();
}

//then in the main I say

  $tpl->assign('header',make_header("bla bla bla");

Is this the best practice? Because after I sort this out I will have my head pretty much around Smarty I think.
_________________
Your online 24/7 box office
http://www.tixrus.us
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Feb 27, 2004 1:07 am    Post subject: Reply with quote

hi,

Instead of using fetch() in this way (which means some of your layout display logic is in your php code) you can consider using the {include} functionality which does the same thing.

In you main template, use something like:
Code:
{include file="header.tpl" header=$header_data}

This will include the template at that position in the current template with the passed value, $header which can then be referenced in the included template.

Your make_header() should return an array of vars to the assignment which will later be passed to the included template.

HTH
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General 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