I’m excluding templates from a plugin like this
$e = &$modx->Event;
switch($e->name) {
case 'OnWebPagePrerender':
if ($modx->documentObject['template'] != $exclude) {
do some code
}
break;
}
based on
http://modxcms.com/forums/index.php/topic,33316.0.html
&exclude=Exclude Template;int;
NOW, how would I go to make a comma separeted list of id’s to ecxlude.
I guess I need to use an array... Any advice welcome!!
-
☆ A M B ☆
- 24,524 Posts
Why bother with an array? Use the strpos($exclude, ’,’ . $modx->documentObject[’template’] . ’,’) function; it’ll return false if the string doesn’t exist. Add the commas on either side to eliminate matches on bigger numbers (35, for example, and you want to exlude 3). To deal with first and last ones, I would simplify things and just use a kludge of adding a 0 to the beginning and end of the list (or some other number or character you know will never get matched). You could work up a fancy regular expression to look for matches including the first and last item, but I’m far too lazy to even try.
THANK YOU SO MUCH!!!
Works:
$e = &$modx->Event;
$exclude2 = ",".$exclude.",";
$template = strpos($exclude2,','.$modx->documentObject['template'].',');
switch ($e->name) {
case "OnWebPagePrerender":
if ($template === false) {
do some code
}
else {
do some code
}
break;
default :
return;
break;
}
&exclude=Exclude Templates;string;