Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
{loop}{/loop} или {foreach}{/foreach}, то, как мне кажется, проблем возникнуть не должно. Если ошибся — поправьте. Желательно с примерами :)if (in_array($value, $this->_blocks[$key]) === false) {
array_push($this->_blocks[$key], $value);
}<code>{block name=«foo»}It's a parent{/block}</code><code>{extends template=«parent.tpl»}
{block name=«foo»}It's a child{/block}
{/extends}</code><code>{extends template=«parent.tpl»}
{block name=«foo»}It's a child{/block}
{/extends}</code>
public function addMessage($text, $type = 'Error') {
if (empty($text)) return true;
if (empty($type))
$type = 'Error';
$this->_messages[$type][] = $text;
return true;
}
public function getMessages($type = 'Error') {
if (empty($type)) {
$type = 'Error';
}
$aMessages = isset($this->_messages[$type]) ? $this->_messages[$type] : false;
$this->_messages[$type] = null;
return $aMessages;
}
{assign var="aFailureMessages" value=$Application->getMessages('Error')}
{assign var="aSuccessfulMessages" value=$Application->getMessages('Success')}
{assign var="aInformativeMessages" value=$Application->getMessages('Informative')}
{if $aFailureMessages || $aSuccessfulMessages || $aInformativeMessages}
<table width="100%" cellspacing="0" cellspacing="0" border="0">
{if $aFailureMessages}
<tr>
<td class="error_box_red">
{section name=failure loop=$aFailureMessages}
{$aFailureMessages[failure]}
{/section}
</td>
</tr>
<tr><td> </td></tr>
{/if}
{if $aSuccessfulMessages}
<tr>
<td class="error_box_green">
{section name=success loop=$aSuccessfulMessages}
{$aSuccessfulMessages[success]}
{/section}
</td>
</tr>
<tr><td> </td></tr>
{/if}
{if $aInformativeMessages}
<tr>
<td class="error_box_blue">
{section name=informative loop=$aInformativeMessages}
{$aInformativeMessages[informative]}
{/section}
</td>
</tr>
<tr><td> </td></tr>
{/if}
</table>
{/if}
if (!is_null($content)) {
return $smarty->fetch($params['template'], ...);
}
return false;
array_push($this->_blocks[$key], $value);
array_unshift($this->_blocks[$key], $value);
a.tpl
----
{block name=head}parent{/block}
----
b.tpl
----
{extends template="a.tpl"}
{block name="head"}child{/block}
{/extends}
{extends template="a.tpl"}{/extends}
---
child child
<?php
function smarty_block_block($params, $content, $smarty)
{
if ( !array_key_exists('name', $params) )
{
$smarty->trigger_error('Block name is not set');
}
$name = $params['name'];
if ( !$smarty->isBlockSet($name) && !is_null($content) )
{
$smarty->setBlock($name, $content);
}
if ( !is_null($content) )
{
return $smarty->getBlock($name);
}
}
?>
<?php
function smarty_block_extends($params, $content, $smarty)
{
if ( !array_key_exists('template', $params) )
{
$smarty->trigger_error('Plese set extending template name!');
}
// if open tag
if ( is_null($content) )
{
$smarty->openBlocksScope();
}
else
{
$content = $smarty->fetch($params['template']);
$smarty->closeBlocksScope();
return $content;
}
return '';
}
?>
protected $_blocks = array(array());
protected $_blocksScope = 0;
...
public function openBlocksScope()
{
$this->_blocksScope++;
$this->_blocks[$this->_blocksScope] = array();
}
public function closeBlocksScope()
{
if ( $this->_blocksScope > 0 )
{
$this->_blocks[$this->_blocksScope] = array();
$this->_blocksScope--;
}
}
public function isBlockSet($key)
{
return array_key_exists($key, $this->_blocks[$this->_blocksScope]) !== false;
}
public function setBlock($key, $value)
{
$this->_blocks[$this->_blocksScope][$key] = $value;
}
public function getBlock($key)
{
if (array_key_exists($key, $this->_blocks[$this->_blocksScope]))
{
return $this->_blocks[$this->_blocksScope][$key];
}
return '';
}
$this->register_outputfilter( array(&$this, 'gz_compress') );$smarty->fetch($params['template']); а второй уже при выводе шаблона display()).
Наследование шаблонов в Smarty