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 | |
$a = "abc"; | |
$b = "def"; | |
$c = "ghi"; | |
return array($a, $b, $c); |
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 | |
class Webdev { | |
function runAsFunction($name,$params = []){ | |
global $modx; | |
if($s = $modx->getObject('modSnippet', [ | |
'name' => $name, | |
])){ | |
$s->loadScript(); | |
$f = $s->getScriptName(); | |
// $params = array('foo' => $foo); |
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 | |
if($s = $modx->getObject('modSnippet', [ | |
'name' => 'имя сниппета', | |
])){ | |
$s->loadScript(); | |
$f = $s->getScriptName(); | |
$params = array('foo' => $foo); | |
$func = $f($params); | |
return $func; | |
} |
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
// class | |
<?php | |
global $modx; | |
class Webdev extends xPDOSimpleObject { | |
function __construct(modX &$modx) { | |
$this->modx =& $modx; | |
} | |
function runAsFunction($name,$params = []){ | |
global $modx; | |
if($s = $modx->getObject('modSnippet', [ |
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 | |
public function getFunctions() | |
{ | |
return array( | |
new Twig_SimpleFunction('snippetC', function ($snippetName, $params = array()) { | |
global $modx; | |
$cacheManager = $modx->getCacheManager(); | |
if($snipetFromCache = $cacheManager->get($snippetName)){ | |
return $snipetFromCache; | |
} else { |
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 | |
// snippet | |
<?php | |
$array = array( | |
"foo" => "bar", | |
"bar" => "foo", | |
100 => -100, | |
200 => 100, | |
); | |
$modx->smarty->assign('array',$array); |
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 | |
// foreachTwig snippet | |
$array = array( | |
"foo" => "bar", | |
"bar" => "foo", | |
100 => -100, | |
200 => 100, | |
); | |
$modx->twig->addGlobal('array' , $array); | |
//template testTwig |
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 | |
// snippet foreach | |
$array = array( | |
"foo" => "bar", | |
"bar" => "foo", | |
100 => -100, | |
200 => 100, | |
); | |
foreach ($array as $key => $value){ | |
echo '[[$foreach? &key=`'.$key.'` , &value=`'.$value.'`]]'; |
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
{% for object in blogData.object %} | |
{% if object.parent == 1 %} | |
<a href="{{ link(object.id) }}"><h2>{{ object.pagetitle }}</h2></a> | |
<p>Опубликовано {{ object.publishedon|date("d/m/Y") }}</p> | |
<p>{{ object.content }}</p> | |
<hr> | |
{% endif %} | |
{% endfor %} |
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 | |
// вызываем наш сниппет | |
$modx->runSnippet('proc'); | |
// инитиализируем шаблон | |
return $modx->twig->render('index.twig'); | |
?> |