Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Blocks (captures), fetch and templating scenario

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


Joined: 08 Jan 2004
Posts: 1

PostPosted: Thu Jan 08, 2004 10:24 am    Post subject: Blocks (captures), fetch and templating scenario Reply with quote

Hello.

In my previous projects I was using other, simple template engine. Because of it I used to following site templating scenario:
one template file for main site design, like

main.tpl
Code:

<html>
<body>
 header
 my site<br />

 {$contents}

 footer
</body>
</html>


and for processing site contents to $contents variable from blocks (in smarty-captures) in other one template file(containing all blocks, I need). example:

blocks.tpl
Code:

{capture name="block_results"}
   
   <table>
   <th> {$usefull_list} </th>
    ... (results)
    </table>
{/capture}

{capture name="usefull_list"}
    <select>
    {foreach item=$my_list}
         <option value={$my_list.value}>{$my_list.name}</option>
    {/foreach}
    </select>
{/capture}


Like you see, I am using one block in another, ant to display $usefull_list in $result capture, i need to process it somehow. Wrote code somthing like this:

index.php
Code:

...
 $smarty->assign('my_list', $array);

 $smarty->fetch('blocks.tpl');

 $smarty->assign('usefull_list', $smarty->_capture_vars['usefull_list']);
 $smarty->assign('contents', $smarty->_capture_vars['block_results']);

 $smarty->display('main.tpl');



The problem is, that i will not see correct $block_results with $usefull_list inside it. To have $usefull list inside, I must assign $usefull_list to smarty variable, then $block_results to variable, and reprocess smarty variable containing $block_results(to put $usefull_list into it). Now I know only one way to process variable - with $smarty->fetch method. But it processes only template file, not a variable.

Q1: how reprocess (re-fetch) a variable?.

Q2: Is there more convenient way to use blocks from separate file, not with $smarty->_capture_vars[]?

Don't want to fetch whole template file to make some changes in one block.. Don't want to have separate file for each block. So, any solution (if not tired to read :)
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Jan 08, 2004 10:33 am    Post subject: Reply with quote

first: since Smarty-2.6.0 you can use "{capture assign=var_name} ..." to assign the captured-contents directly to a variable.

second: you make things overly complicated by the fact that you don't want to have a template for each block. you are most flexible if you use a single template-file for each block.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development 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