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

{block}creates 2sets of code in .tpl.php(1st w content=NULL)

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
vorapoap
Smarty Rookie


Joined: 22 Dec 2009
Posts: 32

PostPosted: Fri Dec 17, 2010 4:51 pm    Post subject: {block}creates 2sets of code in .tpl.php(1st w content=NULL) Reply with quote

Here is the sample code.. I registerPlugin for block call json
Code:

public function _block_json($params, $content) {
      if ($content == NULL) return;
      if ($params['assign']) {
         $assign = $params['assign'];
      } else {
         list($assign) = array_keys($params);
      }
      $json = json_decode($content);
   $this->assign($assign, $json);
   }


In .tpl

Code:

{json assign=groupForm}
[
   { "name":"group_name","type":"text" },
   { "name":"group_tag","type":"text" }
]
{/json}


There is one block call in above .tpl
However, in the final .tpl.php
There are 2 calls making to this _block_json function in run-time
The first one with $content = NULL
The second one with $content = actual content.

Code:

<?php $_smarty_tpl->smarty->_tag_stack[] = array('json', array('assign'=>'groupForm')); $_block_repeat=true; $_smarty_tpl->smarty->registered_plugins['block']['json'][0][0]->_block_json(array('assign'=>'groupForm'), null, $_smarty_tpl, $_block_repeat);while ($_block_repeat) { ob_start();?>

[
   { "name":"group_name","type":"text" },
   { "name":"group_tag","type":"text" }
]
<?php $_block_content = ob_get_clean(); $_block_repeat=false; echo $_smarty_tpl->smarty->registered_plugins['block']['json'][0][0]->_block_json(array('assign'=>'groupForm'), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack);?>



^^See the second line with null as a second parameter

$_smarty_tpl->smarty->registered_plugins['block']['json'][0][0]->_block_json(array('assign'=>'groupForm'), null, $_smarty_tpl, $_block_repeat);while ($_block_repeat) { ob_start();?>
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Dec 17, 2010 5:15 pm    Post subject: Reply with quote

Read the documentation

http://www.smarty.net/docs/en/plugins.block.functions.tpl

It's intended behaviour. Block functions get call twice, once at the opening tags and second on the closing tag.
Back to top
View user's profile Send private message
vorapoap
Smarty Rookie


Joined: 22 Dec 2009
Posts: 32

PostPosted: Mon Dec 20, 2010 7:15 pm    Post subject: Reply with quote

Oh. I kept being ignorance about this!

Thank you again!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs 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