public function before(PHPTAL_Php_CodeWriter $codewriter) { $this->var = $codewriter->createTempVariable(); // alias to repeats handler to avoid calling extra getters on each variable access $codewriter->doSetVar($this->var, '$ctx->repeat'); list($varName, $expression) = $this->parseSetExpression($this->expression); $code = $codewriter->evaluateExpression($expression); // instantiate controller using expression $codewriter->doSetVar($this->var . '->' . $varName, 'new PHPTAL_RepeatController(' . $code . ')' . "\n"); $codewriter->pushContext(); // Lets loop the iterator with a foreach construct $codewriter->doForeach('$ctx->' . $varName, $this->var . '->' . $varName); }
public function before(PHPTAL_Php_CodeWriter $codewriter) { $expressions = $codewriter->splitExpression($this->expression); $definesAnyNonGlobalVars = false; foreach ($expressions as $exp) { list($defineScope, $defineVar, $expression) = $this->parseExpression($exp); if (!$defineVar) { continue; } $this->_defineScope = $defineScope; if ($defineScope != 'global') { $definesAnyNonGlobalVars = true; } // <span tal:define="global foo" /> should be invisible, but <img tal:define="bar baz" /> not if ($this->_defineScope != 'global' && !$this->_pushedContext) { $codewriter->pushContext(); $this->_pushedContext = true; } $this->_defineVar = $defineVar; if ($expression === null) { // no expression give, use content of tag as value for newly defined // var. $this->bufferizeContent($codewriter); continue; } $code = $codewriter->evaluateExpression($expression); if (is_array($code)) { $this->chainedDefine($codewriter, $code); } elseif ($code == PHPTAL_Php_TalesInternal::NOTHING_KEYWORD) { $this->doDefineVarWith($codewriter, 'null'); } else { $this->doDefineVarWith($codewriter, $code); } } // if the content of the tag was buffered or the tag has nothing to tell, we hide it. if ($this->_buffered || !$definesAnyNonGlobalVars && !$this->phpelement->hasRealContent() && !$this->phpelement->hasRealAttributes()) { $this->phpelement->hidden = true; } }