mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-02 10:16:41 +03:00
Support for context passed into a partial as an argument
This commit is contained in:
parent
e6b4182a75
commit
3229ad7c45
@ -154,7 +154,7 @@ class Handlebars_Template
|
|||||||
array_push($this->_stack, array(0, $newStack, false));
|
array_push($this->_stack, array(0, $newStack, false));
|
||||||
$buffer .= $this->_inverted($context, $current);
|
$buffer .= $this->_inverted($context, $current);
|
||||||
array_pop($this->_stack);
|
array_pop($this->_stack);
|
||||||
break;
|
break;
|
||||||
case Handlebars_Tokenizer::T_COMMENT :
|
case Handlebars_Tokenizer::T_COMMENT :
|
||||||
$buffer .= '';
|
$buffer .= '';
|
||||||
break;
|
break;
|
||||||
@ -297,7 +297,7 @@ class Handlebars_Template
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process partial section
|
* Process partial section
|
||||||
*
|
*
|
||||||
@ -309,6 +309,11 @@ class Handlebars_Template
|
|||||||
private function _partial($context, $current)
|
private function _partial($context, $current)
|
||||||
{
|
{
|
||||||
$partial = $this->handlebars->loadPartial($current[Handlebars_Tokenizer::NAME]);
|
$partial = $this->handlebars->loadPartial($current[Handlebars_Tokenizer::NAME]);
|
||||||
|
|
||||||
|
if ( $current[Handlebars_Tokenizer::ARGS] ) {
|
||||||
|
$context = $context->get($current[Handlebars_Tokenizer::ARGS]);
|
||||||
|
}
|
||||||
|
|
||||||
return $partial->render($context);
|
return $partial->render($context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,12 @@ class Handlebars_Tokenizer
|
|||||||
default:
|
default:
|
||||||
if ($this->tagChange($this->ctag, $text, $i)) {
|
if ($this->tagChange($this->ctag, $text, $i)) {
|
||||||
// Sections (Helpers) can accept parameters
|
// Sections (Helpers) can accept parameters
|
||||||
if ($this->tagType == self::T_SECTION) {
|
// Same thing for Partials (little known fact)
|
||||||
|
if (
|
||||||
|
($this->tagType == self::T_SECTION)
|
||||||
|
|| ($this->tagType == self::T_PARTIAL)
|
||||||
|
|| ($this->tagType == self::T_PARTIAL_2)
|
||||||
|
) {
|
||||||
$newBuffer = explode(' ', trim($this->buffer), 2);
|
$newBuffer = explode(' ', trim($this->buffer), 2);
|
||||||
$args = '';
|
$args = '';
|
||||||
if (count($newBuffer) == 2) {
|
if (count($newBuffer) == 2) {
|
||||||
|
Loading…
Reference in New Issue
Block a user