push() public method

Push new local scope on the stack.
public push ( ) : boolean
return boolean
 /**
  * Renders the current node
  *
  * @param LiquidContext $context
  * @return string
  */
 public function render(&$context)
 {
     $collection = $context->get($this->collection_name);
     if (!is_array($collection)) {
         die(debug('not array', $collection));
     }
     // discard keys
     $collection = array_values($collection);
     if (isset($this->attributes['limit']) || isset($this->attributes['offset'])) {
         $limit = $context->get($this->attributes['limit']);
         $offset = $context->get($this->attributes['offset']);
         $collection = array_slice($collection, $offset, $limit);
     }
     $length = count($collection);
     $cols = $context->get($this->attributes['cols']);
     $row = 1;
     $col = 0;
     $result = "<tr class=\"row1\">\n";
     $context->push();
     foreach ($collection as $index => $item) {
         $context->set($this->variable_name, $item);
         $context->set('tablerowloop', array('length' => $length, 'index' => $index + 1, 'index0' => $index, 'rindex' => $length - $index, 'rindex0' => $length - $index - 1, 'first' => (int) ($index == 0), 'last' => (int) ($index == $length - 1)));
         $result .= "<td class=\"col" . ++$col . "\">" . $this->render_all($this->_nodelist, $context) . "</td>";
         if ($col == $cols && !($index == $length - 1)) {
             $col = 0;
             $result .= "</tr>\n<tr class=\"row" . ++$row . "\">";
         }
     }
     $context->pop();
     $result .= "</tr>\n";
     return $result;
 }
Example #2
0
 function test_add_item_in_inner_scope()
 {
     $this->context->push();
     $this->context->set('test', 'test');
     $this->assertEqual('test', $this->context->get('test'));
     $this->context->pop();
     $this->assertEqual(null, $this->context->get('test'));
 }
 /**
  * Render the tag
  *
  * @param LiquidContext $context
  */
 public function render(&$context)
 {
     $context->push();
     $logicalRegex = new LiquidRegexp('/\\s+(and|or)\\s+/');
     $conditionalRegex = new LiquidRegexp('/(' . LIQUID_QUOTED_FRAGMENT . ')\\s*([=!<>a-z_]+)?\\s*(' . LIQUID_QUOTED_FRAGMENT . ')?/');
     $result = '';
     foreach ($this->_blocks as $i => $block) {
         if ($block[0] == 'else') {
             $result = $this->render_all($block[2], $context);
             break;
         }
         if ($block[0] == 'if' || $block[0] == 'elsif') {
             /* Extract logical operators */
             $logicalRegex->match($block[1]);
             $logicalOperators = $logicalRegex->matches;
             array_shift($logicalOperators);
             /* Extract individual conditions */
             $temp = $logicalRegex->split($block[1]);
             $conditions = array();
             foreach ($temp as $condition) {
                 if ($conditionalRegex->match($condition)) {
                     $left = isset($conditionalRegex->matches[1]) ? $conditionalRegex->matches[1] : null;
                     $operator = isset($conditionalRegex->matches[2]) ? $conditionalRegex->matches[2] : null;
                     $right = isset($conditionalRegex->matches[3]) ? $conditionalRegex->matches[3] : null;
                     array_push($conditions, array('left' => $left, 'operator' => $operator, 'right' => $right));
                 } else {
                     throw new LiquidException("Syntax Error in tag 'if' - Valid syntax: if [condition]");
                 }
             }
             if (count($logicalOperators)) {
                 /* If statement contains and/or */
                 $display = true;
                 foreach ($logicalOperators as $k => $logicalOperator) {
                     if ($logicalOperator == 'and') {
                         $display = $this->interpret_condition($conditions[$k]['left'], $conditions[$k]['right'], $conditions[$k]['operator'], $context) && $this->interpret_condition($conditions[$k + 1]['left'], $conditions[$k + 1]['right'], $conditions[$k + 1]['operator'], $context);
                     } else {
                         $display = $this->interpret_condition($conditions[$k]['left'], $conditions[$k]['right'], $conditions[$k]['operator'], $context) || $this->interpret_condition($conditions[$k + 1]['left'], $conditions[$k + 1]['right'], $conditions[$k + 1]['operator'], $context);
                     }
                 }
             } else {
                 /* If statement is a single condition */
                 $display = $this->interpret_condition($conditions[0]['left'], $conditions[0]['right'], $conditions[0]['operator'], $context);
             }
             if ($display) {
                 $result = $this->render_all($block[2], $context);
                 break;
             }
         }
     }
     $context->pop();
     return $result;
 }
 /**
  * Renders the tag
  *
  * @param LiquidContext $context
  */
 public function render(&$context)
 {
     if (!isset($context->registers['for'])) {
         $context->registers['for'] = array();
     }
     $collection = $context->get($this->_collectionName);
     if (is_null($collection) || !is_array($collection) || count($collection) == 0) {
         return '';
     }
     $range = array(0, count($collection));
     if (isset($this->_attributes['limit']) || isset($this->_attributes['offset'])) {
         $offset = 0;
         if (isset($this->_attributes['offset'])) {
             $offset = $this->_attributes['offset'] == 'continue' ? $context->registers['for'][$this->_name] : $context->get($this->_attributes['offset']);
         }
         //$limit = $context->get($this->_attributes['limit']);
         $limit = isset($this->_attributes['limit']) ? $context->get($this->_attributes['limit']) : null;
         $range_end = $limit ? $limit : count($collection) - $offset;
         $range = array($offset, $range_end);
         $context->registers['for'][$this->_name] = $range_end + $offset;
     }
     $result = '';
     $segment = array_slice($collection, $range[0], $range[1]);
     if (!count($segment)) {
         return null;
     }
     $context->push();
     $length = count($segment);
     /**
      * @todo If $segment keys are not integer, forloop not work
      * array_values is only a little help without being tested.
      */
     $segment = array_values($segment);
     foreach ($segment as $index => $item) {
         $context->set($this->_variableName, $item);
         $context->set('forloop', array('name' => $this->_name, 'length' => $length, 'index' => $index + 1, 'index0' => $index, 'rindex' => $length - $index, 'rindex0' => $length - $index - 1, 'first' => (int) ($index == 0), 'last' => (int) ($index == $length - 1)));
         $result .= $this->renderAll($this->_nodelist, $context);
     }
     $context->pop();
     return $result;
 }
 /**
  * Renders the node
  *
  * @param LiquidContext $context
  */
 public function render(&$context)
 {
     $context->push();
     $result = $this->_document->render($context);
     $context->pop();
     return $result;
 }
 /**
  * Renders the node
  *
  * @param LiquidContext $context
  */
 public function render(&$context)
 {
     $result = '';
     $variable = $context->get($this->_variable);
     $context->push();
     foreach ($this->_attributes as $key => $value) {
         $context->set($key, $context->get($value));
     }
     if ($this->_collection) {
         foreach ($variable as $item) {
             $context->set($this->_templateName, $item);
             $result .= $this->_document->render($context);
         }
     } else {
         if (!is_null($this->_variable)) {
             $context->set($this->_templateName, $variable);
         }
         $result .= $this->_document->render($context);
     }
     $context->pop();
     return $result;
 }