Skip to content

Instantly share code, notes, and snippets.

View sonicpunk's full-sized avatar

Benjamin Davis sonicpunk

View GitHub Profile
@sonicpunk
sonicpunk / getLevel
Created May 29, 2013 13:34
MODX snippet:returns the level of a resource
<?php
$id = isset($id) ? $id : $modx->resource->get('id');
$pids = $modx->getParentIds($id, 100, array('context' => 'web'));
return count($pids);
@sonicpunk
sonicpunk / findTemplateID
Created May 29, 2013 13:30
MODX snippet: finds all resources with a specified template and writes a list of ids
<?php
$c = $modx->newQuery('modResource');
$resIds = array();
/* we only want published and undeleted resources */
$c->where(array(
'published' => true,
'deleted' => false,
'template'=>$templateID
));
$resources = $modx->getCollection('modResource',$c);
@sonicpunk
sonicpunk / checkTemplate
Created May 29, 2013 13:20
MODX Snippet. According to the given template ID you can include or exclude a specific HTML chunk.
//[[checkTemplate? &templateID=`1` &tpl=`bxsliderjs`]]
<?php
$output='';
$template=$modx->resource->get('template');
if($exclude!=1){
if($template==$templateID){
$output.=$modx->getChunk($tpl);
};
@sonicpunk
sonicpunk / ifElseTemplate
Created May 29, 2013 13:16
MODX Snippet. Decide which HTML chunk to output based on what template ID you are looking for.
//Snippet Call [[ifElseTemplate? &ifId=`1` &ifTpl=`kontakt_info` &elseId=`4` &elseTpl=`kontakt_person_info`]]
<?php
$output='';
$template=$modx->resource->get('template');
if($template==$ifId){
$output.=$modx->getChunk($ifTpl);
}else if($template==$elseId){
$output.=$modx->getChunk($elseTpl);