public function getChunk($chunkName, array $properties= array ()) { $output= ''; if (array_key_exists($chunkName, $this->sourceCache['modChunk'])) { $chunk = $this->newObject('modChunk'); $chunk->fromArray($this->sourceCache['modChunk'][$chunkName]['fields'], '', true, true); $chunk->setPolicies($this->sourceCache['modChunk'][$chunkName]['policies']); } else { $chunk= $this->getObject('modChunk', array ('name' => $chunkName), true); if (!empty($chunk) || $chunk === '0') { $this->sourceCache['modChunk'][$chunkName]= array ( 'fields' => $chunk->toArray(), 'policies' => $chunk->getPolicies() ); } } if (!empty($chunk) || $chunk === '0') { $chunk->setCacheable(false); $output= $chunk->process($properties); } return $output; }
<?php ini_set("display_errors",1); $data=''; $phs=isset($phs)?explode(",",$phs):array(); if(isset($tpl,$phs) && $tpl!='' && count($phs)>0){ foreach($phs as $item){ $data.=$modx->parseChunk($tpl,array('item'=>$item,'time'=>time())); } } return $data;
<p><b>[[+time]]</b>: [[+item]] - [[!phpthumbof? &input=`[[+item]]` &options=`&h=150&f=jpg`]]</p>
[[!test? &tpl=`test` &phs=`/assets/1.jpg,/assets/2.jpg`]]
[[!test? &tpl=`test` &phs=`/assets/1.jpg,/assets/2.jpg`]]
public function processElementTags($parentTag, & $content, $processUncacheable= false, $removeUnprocessed= false, $prefix= "[[", $suffix= "]]", $tokens= array (), $depth= 0) { $this->_processingTag = true; $this->_processingUncacheable = (boolean) $processUncacheable; $this->_removingUnprocessed = (boolean) $removeUnprocessed; $depth = $depth > 0 ? $depth - 1 : 0; $processed= 0; $tags= array (); /* invoke OnParseDocument event */ $this->modx->documentOutput = $content; $this->modx->invokeEvent('OnParseDocument', array('content' => &$content)); $content = $this->modx->documentOutput; unset($this->modx->documentOutput); if ($collected= $this->collectElementTags($content, $tags, $prefix, $suffix, $tokens)) { $tagMap= array (); foreach ($tags as $tag) { $token= substr($tag[1], 0, 1); if (!$processUncacheable && $token === '!') { if ($removeUnprocessed) { $tagMap[$tag[0]]= ''; } } elseif (!empty ($tokens) && !in_array($token, $tokens)) { $collected--; continue; } if ($tag[0] === $parentTag) { $tagMap[$tag[0]]= ''; $processed++; continue; } $tagOutput= $this->processTag($tag, $processUncacheable); if (($tagOutput === null || $tagOutput === false) && $removeUnprocessed) { $tagMap[$tag[0]]= ''; $processed++; } elseif ($tagOutput !== null && $tagOutput !== false) { $tagMap[$tag[0]]= $tagOutput; if ($tag[0] !== $tagOutput) $processed++; } } $this->mergeTagOutput($tagMap, $content); if ($depth > 0) { $processed+= $this->processElementTags($parentTag, $content, $processUncacheable, $removeUnprocessed, $prefix, $suffix, $tokens, $depth); } } $this->_processingTag = false; return $processed; }
$this->_processingTag = true;
add static $test; echo ++$test."<br />";
$this->modx->invokeEvent('OnParseDocument', array('content' => &$content));
Condition | Iterations |
---|---|
[[snippet]] | 2 |
{{$ chunk}} | 2 |
Empty page | 3 |
[[num? input = `1000`]] | five |
[[* pagetitle: num]] | 6 |
[[num? input = `[[* pagetitle]]`]] | 7 |
Non-existent snippet | 23 |
Nonexistent chunk | 23 |
Source: https://habr.com/ru/post/153261/
All Articles