Re: [SMARTY] Creating custom loop block function

Kaloyan Tsvetkov <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <[email protected]>
Thank you, I will do that. Are you saying that I have to modify the &$repeat
parameter of the block function to make it loop?

What is the correct syntax for addressign smarty vars inside the
{cell}...{/cell} block ?

Here's my compiled template. Here's how I got the idea for reseting &$repeat
to true to keep the while() loop going.

--------
<?php /* Smarty version 2.6.10, created on 2005-12-23 12:04:10
         compiled from proba.html */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('block', 'list', '
proba.html', 8, false),array('block', 'head', 'proba.html', 10,
false),array('block', 'column', 'proba.html', 11, false),array('block',
'rows', 'proba.html', 16, false),array('block', 'cell', 'proba.html', 17,
false),)), $this); ?>
<html>
<head>
<title>List Table Proba</title>

</head>
<body>

    <?php $this->_tag_stack[] = array('list', array('data' =>
$this->_tpl_vars['rows']));
smarty_block_list($this->_tag_stack[count($this->_tag_stack)-1][1], null,
$this, $_block_repeat=true);while ($_block_repeat) { ob_start(); ?>

        <?php $this->_tag_stack[] = array('head', array());
smarty_block_head($this->_tag_stack[count($this->_tag_stack)-1][1], null,
$this, $_block_repeat=true);while ($_block_repeat) { ob_start(); ?>
            <?php $this->_tag_stack[] = array('column', array());
smarty_block_column($this->_tag_stack[count($this->_tag_stack)-1][1], null,
$this, $_block_repeat=true);while ($_block_repeat) { ob_start(); ?>1<?php
$_block_content = ob_get_contents(); ob_end_clean(); echo
smarty_block_column($this->_tag_stack[count($this->_tag_stack)-1][1],
$_block_content, $this, $_block_repeat=false); }
array_pop($this->_tag_stack); ?>
            <?php $this->_tag_stack[] = array('column', array());
smarty_block_column($this->_tag_stack[count($this->_tag_stack)-1][1], null,
$this, $_block_repeat=true);while ($_block_repeat) { ob_start(); ?>2<?php
$_block_content = ob_get_contents(); ob_end_clean(); echo
smarty_block_column($this->_tag_stack[count($this->_tag_stack)-1][1],
$_block_content, $this, $_block_repeat=false); }
array_pop($this->_tag_stack); ?>
            <?php $this->_tag_stack[] = array('column', array());
smarty_block_column($this->_tag_stack[count($this->_tag_stack)-1][1], null,
$this, $_block_repeat=true);while ($_block_repeat) { ob_start(); ?>3<?php
$_block_content = ob_get_contents(); ob_end_clean(); echo
smarty_block_column($this->_tag_stack[count($this->_tag_stack)-1][1],
$_block_content, $this, $_block_repeat=false); }
array_pop($this->_tag_stack); ?>
        <?php $_block_content = ob_get_contents(); ob_end_clean(); echo
smarty_block_head($this->_tag_stack[count($this->_tag_stack)-1][1],
$_block_content, $this, $_block_repeat=false); }
array_pop($this->_tag_stack); ?>

        <?php $this->_tag_stack[] = array('rows', array());
smarty_block_rows($this->_tag_stack[count($this->_tag_stack)-1][1], null,
$this, $_block_repeat=true);while ($_block_repeat) { ob_start(); ?>
            <?php $this->_tag_stack[] = array('cell', array());
smarty_block_cell($this->_tag_stack[count($this->_tag_stack)-1][1], null,
$this, $_block_repeat=true);while ($_block_repeat) { ob_start(); ?>


                0. <?php echo $this->_tpl_vars['SKU']; ?>
 <?php echo $this->_tpl_vars['data']['SKU']; ?>


            <?php $_block_content = ob_get_contents(); ob_end_clean(); echo
smarty_block_cell($this->_tag_stack[count($this->_tag_stack)-1][1],
$_block_content, $this, $_block_repeat=false); }
array_pop($this->_tag_stack); ?>
            <?php $this->_tag_stack[] = array('cell', array());
smarty_block_cell($this->_tag_stack[count($this->_tag_stack)-1][1], null,
$this, $_block_repeat=true);while ($_block_repeat) { ob_start(); ?>

                 0. <?php echo $this->_tpl_vars['brand']; ?>
 <?php echo $this->_tpl_vars['data']['brand']; ?>


            <?php $_block_content = ob_get_contents(); ob_end_clean(); echo
smarty_block_cell($this->_tag_stack[count($this->_tag_stack)-1][1],
$_block_content, $this, $_block_repeat=false); }
array_pop($this->_tag_stack); ?>
            <?php $this->_tag_stack[] = array('cell', array());
smarty_block_cell($this->_tag_stack[count($this->_tag_stack)-1][1], null,
$this, $_block_repeat=true);while ($_block_repeat) { ob_start(); ?>

                <?php echo '
                    0. {$row_each.brand}
                '; ?>


            <?php $_block_content = ob_get_contents(); ob_end_clean(); echo
smarty_block_cell($this->_tag_stack[count($this->_tag_stack)-1][1],
$_block_content, $this, $_block_repeat=false); }
array_pop($this->_tag_stack); ?>
        <?php $_block_content = ob_get_contents(); ob_end_clean(); echo
smarty_block_rows($this->_tag_stack[count($this->_tag_stack)-1][1],
$_block_content, $this, $_block_repeat=false); }
array_pop($this->_tag_stack); ?>
    <?php $_block_content = ob_get_contents(); ob_end_clean(); echo
smarty_block_list($this->_tag_stack[count($this->_tag_stack)-1][1],
$_block_content, $this, $_block_repeat=false); }
array_pop($this->_tag_stack); ?>


</body>
</html>
--------

On 12/23/05, messju mohr <[email protected]> wrote:
>
> On Fri, Dec 23, 2005 at 01:27:50PM +0200, Kaloyan Tsvetkov wrote:
> > The problem is that the Smarty variable calls({$SKU}, or {$data.SKU}, or
> > whatever is the propper Smarty syntax) from {cell}..{/cell} are not
> working.
> > These {cell} tags are parsed only one time, and we can not put new
> values in
> > them each time we need a new row parsed. These {cell} tags are parsed
> even
> > before the first smarty_block_list() call - check the compiled version
> of
> > the template for proof.
>
> wrong. reread http://smarty.php.net/manual/en/plugins.block.functions.php
> and maybe reread your compiled template.
>
> > How Smarty works (correct me if I am wrong about something) - first it
> > analyzes the template (smarty syntax), then it creates the compiled
> version
> > of the template (php script in the smarty_compiled folder), then this
> > compiled version is included and run. Running the included compiled
> version
> > triggers the block functions that are declared in them.
> >
> > When we use {section} or {foreach} (which are core Smarty plugins),
> Smarty
> > adds special code in the compiled versions, which handle the access to
> data
> > for each iteration loop. That's what we lack when we do our {row} block
> tag.
>
> wrong. see above.
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.