Re: Q: how to use display() for dynamic embedded tables
| From: | Anders Janson | Date: | Wed, 07 Nov 2001 09:38:47 +0000 |
| Subject: | Re: Q: how to use display() for dynamic embedded tables | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1838@lists.php.net to get a copy of this message | ||
Joe Rice wrote:
> Hello,
> I'm relatively new to Smarty and have one problem
> i can't figure out. I currently have home.php and home.tpl
> working as expected and I'm using php's sessions to maintain state.
> In home.tpl i have a embedded table that holds a very straight forward
> voting/polling feature. I would like to be able to abstract that
> from home.php and home.tpl to poll.php and poll.tpl respectively.
> As you can imagine doing this wasn't any big feat. Independently
> going to poll.php will display just my poll table. With
> the use of require/include i can get the poll back into
> home.php. The problem is how do i get the newly abstracted
> poll.tpl to embed itself back into home.tpl ?
>
> I'm trying to do this in attempt to allow the space in the
> layout where the poll normally sits to be easily changed
> to something other then the poll feature.
I would do it like this:
- Separate things into "modules" like you do (poll), with a separate
template for the presentation.
- Put a placeholder variable in the master layout template, like
{$PLACEHOLDER}.
- Code something like this:
$poll = new Smarty;
$poll->assign ("whatever", "poll data goes here");
$poll_HTML = $poll->fetch('poll.tpl');
$layout = new Smarty;
$layout->assign ("something", "your other data here");
$layout->assign ("PLACEHOLDER", $poll_HTML);
$layout->display('home.tpl');
Using {include ...} is probably not a good solution if you want to be able
to display other "modules".
Your master layout should not need to be modified if another module is
used.
/Anders