Child pages
  • Add "kDBTagProcessor::prepareBlockParams" helper method [5.3.0-B1]
Skip to end of metadata
Go to start of metadata

To display a list of data (not necessarily taken from database) the following construct in template is used:

<inp2:m_DefineElement name="item_element">
    <li>
		<inp2:m_Param name="sample"/>
	</li>
</inp2:m_DefineElement>
 
<ul>
	<inp2:PrintSomething render_as="item_element"/>
</ul>

The code of "PrintSomething" tag then would look like this:

protected function PrintSomething(array $params)
{
	$ret = '';
	$block_params = $this->prepareTagParams($params);
	$block_params['name'] = $params['render_as'];
 
	foreach ( $data as $item ) {
	    $block_params['sample'] = $item['SampleData'];
		$ret .= $this->Application->ParseBlock($block_params);
	}
 
	return $ret;
}

Usually the code in 4th and 5th line never changes, but to preserve backwards compatibility instead of changing "prepareTagParams" directly I'm proposing to add new method called "prepareBlockParams" that would do just that.

Solution

Create "kDBTagProcessor::prepareBlockParams" method with following content:

protected function prepareBlockParams(array $params)
{
	$block_params = $this->prepareTagParams($params);
	$block_params['name'] = $params['render_as'];

	return $block_params;
}

Related Tasks