public function render(OOTemplate_Context $context) { $result = ""; $bits = $this->_token->split(); if (sizeof($bits) != 4) { throw new OOTemplate_Exception(sprintf("'rand' statements should use the format : 'rand var in array' : %s", $this->_token->contents())); } list(, $var, , $key) = $bits; $data = $context->get($key, null); if (is_null($data) || !$data instanceof Traversable) { throw new OOTemplate_Exception(sprintf("'rand' tag received an invalid argument : %s", $this->_token->contents())); } $current = clone $context; try { $data = (array) $data->getDicts(); shuffle($data); $current->set($var, current($data)); foreach ($this->_nodes as $node) { $result .= $node->render($current); } } catch (OOTemplate_Exception $e) { } return $result; foreach ($this->_if_nodes as $node) { $result .= $node->render($context); } return $result; }
public function render(OOTemplate_Context $context) { $bits = $this->_token->split(); unset($bits[0]); $result = ""; $not = false; foreach ($bits as $bit) { if ($bit == 'not') { $not = !$not; continue; } try { if (($var_exists = $context->get($bit, null)) === null) { throw new OOTemplate_Exception(); } $parse = !empty($var_exists) && !$not; } catch (OOTemplate_Exception $e) { $parse = (bool) $not; } } if ($parse) { foreach ($this->_if_nodes as $node) { $result .= $node->render($context); } } else { foreach ($this->_el_nodes as $node) { $result .= $node->render($context); } } return $result; }
public function render(OOTemplate_Context $context) { $result = ""; list(, $o, , $var) = $this->_token->split(); try { if (is_null($o) || is_null($var)) { throw new OOTemplate_Exception(sprintf("'for' statements should use the format : 'for x in y' : %s", $this->_token->contents())); } if (!$context->has_key($var)) { throw new OOTemplate_Exception(sprintf("'for' tag received an invalid argument : %s", $this->_token->contents())); } $current = clone $context; foreach ($context->get($var) as $each) { $current->set($o, $each->getDicts()); foreach ($this->_nodes as $node) { $result .= $node->render($current); } } } catch (OOTemplate_Exception $e) { OOTemplate_Debug::show($e->getMessage()); } return $result; }