Skip to content

Instantly share code, notes, and snippets.

@leotop
Last active January 31, 2018 07:26
Show Gist options
  • Save leotop/fc5ee1b165e69d62415031b8fb5097b9 to your computer and use it in GitHub Desktop.
Save leotop/fc5ee1b165e69d62415031b8fb5097b9 to your computer and use it in GitHub Desktop.
Обработка тегов {php}{/php}, аналог из шаблонизатора smarty. Особенность, т.к. всегда выполняется как код в контексте основного, то данные в строку передаем через $php_val внутри eval
<?php
// НЕ ИСПОЛЬЗОВАТЬ НА РАБОЧЕМ САЙТЕ
// Плагин сделан с целью изучения
function replace_php_tags($matches){
//$res = $modx->getObject('modResource',1); // Внутри функции вызов не работает, причина пока не известна
$code = $matches[1];
eval($code);
return $php_val;
}
$content = preg_replace_callback("#{php}(.*?){/php}#s", "replace_php_tags", $modx->resource->get('content'));
$modx->resource->set('content', $content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment