/** * getChunkIf * * Copyright 2009-2010 by Jason Coward <[email protected]> and Shaun McCormick * <[email protected]> * * getChunkIf is free software; you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. * * If is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * If; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * @package getChunkIf */ /** * Simple If (conditional) snippet * * @package getChunkIf */ if (!empty($debug)) { print_r($scriptProperties); if (!empty($die)) die(); } if (!empty($scriptProperties['placeholder'])){ $subject = '[[+'.$scriptProperties['placeholder'].']]'; } $modx->parser->processElementTags('',$subject,true,true); $output = ''; $operator = !empty($operator) ? $operator : ''; $operand = !isset($operand) ? '' : $operand; if (isset($subject)) { if (!empty($operator)) { $operator = strtolower($operator); switch ($operator) { case '!=': case 'neq': case 'not': case 'isnot': case 'isnt': case 'unequal': case 'notequal': $outputchunk = (($subject != $operand) ? $thenchunk : (isset($elsechunk) ? $elsechunk : '')); break; case '<': case 'lt': case 'less': case 'lessthan': $outputchunk = (($subject < $operand) ? $thenchunk : (isset($elsechunk) ? $elsechunk : '')); break; case '>': case 'gt': case 'greater': case 'greaterthan': $outputchunk = (($subject > $operand) ? $thenchunk : (isset($elsechunk) ? $elsechunk : '')); break; case '<=': case 'lte': case 'lessthanequals': case 'lessthanorequalto': $outputchunk = (($subject <= $operand) ? $thenchunk : (isset($elsechunk) ? $elsechunk : '')); break; case '>=': case 'gte': case 'greaterthanequals': case 'greaterthanequalto': $outputchunk = (($subject >= $operand) ? $thenchunk : (isset($elsechunk) ? $elsechunk : '')); break; case 'isempty': case 'empty': $outputchunk = empty($subject) ? $thenchunk : (isset($elsechunk) ? $elsechunk : ''); break; case '!empty': case 'notempty': case 'isnotempty': $outputchunk = !empty($subject) && $subject != '' ? $thenchunk : (isset($elsechunk) ? $elsechunk : ''); break; case 'isnull': case 'null': $outputchunk = $subject == null || strtolower($subject) == 'null' ? $thenchunk : (isset($elsechunk) ? $else : ''); break; case 'inarray': case 'in_array': case 'ia': $operand = explode(',',$operand); $outputchunk = in_array($subject,$operand) ? $thenchunk : (isset($elsechunk) ? $elsechunk : ''); break; case '==': case '=': case 'eq': case 'is': case 'equal': case 'equals': case 'equalto': default: $outputchunk = (($subject == $operand) ? $thenchunk : (isset($elsechunk) ? $elsechunk : '')); break; } } } if (!empty($debug)) { var_dump($output); } unset($subject); //echo $outputchunk; //print_r($scriptProperties); return $modx->getChunk($outputchunk);

return $modx->getChunk($outputchunk, array($placeholder => $subject));
if (!empty($scriptProperties['placeholder'])){
$subject = '[[+'.$modx->getPlaceholder($scriptProperties['placeholder']).']]';
}
$modx->parser->processElementTags('',$subject,true,true);
if (!empty($scriptProperties['placeholder'])){
$subject = $modx->getPlaceholder($scriptProperties['placeholder']);
}
<h3>[[+pagetitle]]</h3> [[getChunkIf? &placeholder=`introtext` &operator=`!empty` &thenchunk=`introchunk` &elsechunk=`contentchunk` &resid=`[[+id]]`]]
resid=`[[+id]]`
if ($this->isCacheable() && isset ($this->xpdo->elementCache[$this->_tag])) {
$this->_output = $this->xpdo->elementCache[$this->_tag];
$this->_processed = true;
}