/** * Appends an else control structure to the current body and returns $this. * * Note: This can only called directly after a call to {@link self::_if() if ()} or {@link self::_elseif() _elseif()}. * * The $body parameter can either be an ezcTemplateBodyAstNode element or * an ezcTemplateAstBuilder object in which case the body is taken from * the builder. * * Usually you will call body() and use the result as the $body parameter, * this allows you to specify the statements for the body of the else. * <code> * $cb->_else( $cb->body() * ->assign( "a", 5 ) ); * </code> * This represents the code: * <code> * else * { * $a = 5; * } * </code> * * @param mixed $body The body of the 'else' structure. * @return ezcTemplateAstBuilder */ public function _else($body) { $if = $this->currentBody->getLastStatement(); if (!$if instanceof ezcTemplateIfAstNode) { throw new ezcTemplateInternalException("An 'else' control structure can only be appended right after an 'if' or 'elseif', last statement was <" . get_class($if) . ">"); } $lastCondition = $if->getLastCondition(); if ($lastCondition !== null && $lastCondition->condition === null) { throw new ezcTemplateInternalException("An 'else' control structure can only be appended right after an 'if' or 'elseif', tried placing it after an 'else' control structure."); } if ($body instanceof ezcTemplateAstBuilder) { $body = $body->getAstNode(); } $conditionBody = new ezcTemplateConditionBodyAstNode(null, $body); $if->appendCondition($conditionBody); return $this; }