Last active
January 31, 2018 07:26
-
-
Save leotop/fc5ee1b165e69d62415031b8fb5097b9 to your computer and use it in GitHub Desktop.
Обработка тегов {php}{/php}, аналог из шаблонизатора smarty. Особенность, т.к. всегда выполняется как код в контексте основного, то данные в строку передаем через $php_val внутри eval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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