/**
  * Renders the block
  *
  * @param Context $context
  *
  * @return string
  */
 public function render(Context $context)
 {
     $output = parent::render($context);
     if ($this->lastValue == $output) {
         return '';
     } else {
         $this->lastValue = $output;
         return $this->lastValue;
     }
 }
Beispiel #2
0
 /**
  * Constructor
  *
  * @param string $markup
  * @param Array $tokens
  * @param FileSystem $fileSystem
  *
  * @throws \Liquid\LiquidException
  * @return \Liquid\Tag\TagBlock
  */
 public function __construct($markup, array &$tokens, FileSystem $fileSystem = null)
 {
     $syntaxRegexp = new Regexp('/(\\w+)/');
     if ($syntaxRegexp->match($markup)) {
         $this->block = $syntaxRegexp->matches[1];
         parent::__construct($markup, $tokens, $fileSystem);
     } else {
         throw new LiquidException("Syntax Error in 'block' - Valid syntax: block [name]");
     }
 }
 /**
  * Constructor
  *
  * @param string $markup
  * @param array $tokens
  * @param FileSystem $fileSystem
  *
  * @throws \Liquid\LiquidException
  */
 public function __construct($markup, array &$tokens, FileSystem $fileSystem = null)
 {
     parent::__construct($markup, $tokens, $fileSystem);
     $syntax = new Regexp("/(\\w+)\\s+in\\s+(" . Liquid::get('ALLOWED_VARIABLE_CHARS') . "+)/");
     if ($syntax->match($markup)) {
         $this->variableName = $syntax->matches[1];
         $this->collectionName = $syntax->matches[2];
         $this->extractAttributes($markup);
     } else {
         throw new LiquidException("Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3");
     }
 }
Beispiel #4
0
 /**
  * Constructor
  *
  * @param string $markup
  * @param array $tokens
  * @param FileSystem $fileSystem
  *
  * @throws \Liquid\LiquidException
  */
 public function __construct($markup, array &$tokens, FileSystem $fileSystem = null)
 {
     parent::__construct($markup, $tokens, $fileSystem);
     $syntaxRegexp = new Regexp('/(\\w+)\\s+in\\s+(' . Liquid::get('ALLOWED_VARIABLE_CHARS') . '+)/');
     if ($syntaxRegexp->match($markup)) {
         $this->variableName = $syntaxRegexp->matches[1];
         $this->collectionName = $syntaxRegexp->matches[2];
         $this->name = $syntaxRegexp->matches[1] . '-' . $syntaxRegexp->matches[2];
         $this->extractAttributes($markup);
     } else {
         throw new LiquidException("Syntax Error in 'for loop' - Valid syntax: for [item] in [collection]");
     }
 }
 /**
  * Renders the tag
  *
  * @param Context $context
  *
  * @return string
  *
  */
 public function render(Context $context)
 {
     $this->currentPage = is_numeric($context->get('page')) ? $context->get('page') : 1;
     $this->currentOffset = ($this->currentPage - 1) * $this->numberItems;
     $this->collection = $context->get($this->collectionName);
     $this->collectionSize = count($this->collection);
     $this->totalPages = ceil($this->collectionSize / $this->numberItems);
     $paginatedCollection = array_slice($this->collection, $this->currentOffset, $this->numberItems);
     // Sets the collection if it's a key of another collection (ie search.results, collection.products, blog.articles)
     $segments = explode('.', $this->collectionName);
     if (count($segments) == 2) {
         $context->set($segments[0], array($segments[1] => $paginatedCollection));
     } else {
         $context->set($this->collectionName, $paginatedCollection);
     }
     $paginate = array('page_size' => $this->numberItems, 'current_page' => $this->currentPage, 'current_offset' => $this->currentOffset, 'pages' => $this->totalPages, 'items' => $this->collectionSize);
     if ($this->currentPage != 1) {
         $paginate['previous']['title'] = 'Previous';
         $paginate['previous']['url'] = $this->currentUrl($context) . '?page=' . ($this->currentPage - 1);
     }
     if ($this->currentPage != $this->totalPages) {
         $paginate['next']['title'] = 'Next';
         $paginate['next']['url'] = $this->currentUrl($context) . '?page=' . ($this->currentPage + 1);
     }
     $context->set('paginate', $paginate);
     return parent::render($context);
 }
 /**
  * Renders the block
  *
  * @param Context $context
  *
  * @return string
  */
 public function render(Context $context)
 {
     $output = parent::render($context);
     $context->set($this->to, $output);
     return '';
 }