PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Structures » Structures_DataGrid » Bug #3229

Add ability to add Smarty template variables

Details

Request #3229Add ability to add Smarty template variables
Submitted2005-01-18 15:26 UTC
Fromtfraser at jeffsys dot net
StatusBogus
PackageStructures_DataGrid
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2005-01-18 15:26 UTC] tfraser at jeffsys dot net

Description:
------------
The Structures_DataGrid_Renderer_Smarty class should have the capability of adding template variables to the static set of variables it currently assigns in render(), which are:

$this->_smarty->assign('recordSet', $this->_dg->recordSet);
$this->_smarty->assign('columnSet', $this->_dg->columnSet);
$this->_smarty->assign('recordLimit', $this->_dg->rowLimit);
$this->_smarty->assign('pageList', $this->_dg->pageList);
$this->_smarty->assign('currentPage', $this->_dg->page);

I suppose this could be done using separate templates, one specifically for the above variables, but adding this functionality gives more flexibility, imho.

Reproduce code:
---------------
39a40,41
> var $_vars;
>
50a53
> $this->_vars = array();
71a75,79
> function addVariable($var, $value)
> {
> $this->_vars[$var] = $value;
> }
>
78c86
<
---
>
82c90
<
---
>
89a98,101
> foreach ($this->_vars as $key => $value) {
> $this->_smarty->assign($key, $value);
> }
>

Expected result:
----------------
Usage:

$dg =& new Structures_DataGrid(20,0,DATAGRID_RENDER_SMARTY);
$dg->bind($dataSet);

$e = $dg->renderer->setTemplate("main.htm");
if ($e) echo '<p>',$e->message,'</p>';

$dg->renderer->addVariable("title", "hello title");

$dg->render();

[2005-01-18 19:46 UTC] asnagy at webitecture dot org

Thank you for taking the time to write to us, but this is not
a bug.

This can be done by assigning the needed variable to an existing smarty object, and calling the setSmarty method.

$smarty = new Smarty();
$smarty->assign('foo', $bar);
$dg =& new Structures_DataGrid(null, null, DATAGRID_RENDER_SMARTY);
$dg->renderer->setSmarty($smarty);

This is also the preferred way.