Skip to content

Instantly share code, notes, and snippets.

<?php
$c = $modx->newQuery('modResource');
$c->where(array(
'published' => 1,
'hidemenu' => 0));
$c->sortby('unpub_date','asc');
$c->limit(10);
$resources = $c->getCollection('modResource',$c);
<?php
$tvname = $modx->getOption('tvname',$scriptProperties,'');
if ($tvname == '') { return 'No TV name given'; }
$tv = $modx->getObject('modTemplateVar',array('name' => $tvname));
$tvdesc = $tv->get('description');
return $tvdesc;
@Mark-H
Mark-H / gist:962492
Created May 9, 2011 13:14
Simple snippet (output filter) for MODX Revolution related items. Call as [[snippetname? &tpl=`chunkname` &input=`[[*your-comma-delimited-id-tv]]`]]
<?php
if ($input == null) { return 'No relevant items found.'; }
$tpl = $modx->getOption('tpl',$scriptProperties,null);
if (($tpl === null) || (!$modx->getChunk($tpl))) { return 'No template found'; }
$ids = explode (',', $input);
foreach ($ids as $a => $key) {
$document = $modx->getObject('modResource', array(
'published' => 1,
<?xml version="1.0" encoding="UTF-8"?>
<model package="campermanagement" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
<object class="cmCamper" table="extra_campers" extends="xPDOSimpleObject">
<field key="brand" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="" />
<field key="type" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="plate" dbtype="varchar" precision="255" phptype="string" default="" />
<field key="car" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="engine" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="manufactured" dbtype="int" precision="10" phptype="string" null="false" default="" />
<field key="beds" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="" />
@Mark-H
Mark-H / 1. In the ExtJS form declaration.js
Created May 21, 2011 21:53
Fancy MODX / ExtJS combo-box that searches while typing and adds new entries if they don't exist.
// Call the form with the unique xtype
items: [{
xtype: 'campermgmt-newcamper-form-brandscombo',
fieldLabel: 'Merknaam',
name: 'brand',
id: 'brand',
allowBlank: false,
vtype: 'alphanum'
}
<...>
$queryGraph = array();
if ($includeBrand) { $queryGraph[] = '"Brand":{}'; }
if ($includeImages) { $queryGraph[] = '"Images":{}'; }
if ($includeOwner) { $queryGraph[] = '"Owner":{}'; }
if ($includeOptions) { $queryGraph[] = '"CamperOptions":{ "Options":{} }'; }
$queryGraph = '{ '.implode(', ',$queryGraph).' }';
//echo '<pre>'.print_r($query->query,true).'</pre>';
$campers = $modx->getCollectionGraph('cmCamper',$queryGraph,$query);
@Mark-H
Mark-H / readme.md
Created May 31, 2011 22:29
Create database tables for VisionCart in MODX 2.1+

Use this little snippet to create database tables from the visioncart model to actually use the package when freshly installed.

Put the code in a new snippet, and put the snippet call in any resource. Visit the resource. Try using VisionCart or check your database using PhpMyAdmin to see if the tables were created.

@Mark-H
Mark-H / disabletooltips.plugin.php
Last active March 1, 2016 22:15
Plugin to disable tooltips in MODX globally.
<?php
// Disables tooltips globally.
//
// Create a new plugin and add the following system event: OnManagerPageInit
//
// © 2010 Mark Hamstra <[email protected]>
// Buy me a beer? Paypal hamstra.mark at gmail.com.
//
// Licensed under the MIT license
@Mark-H
Mark-H / simplx_toplaceholders.php
Created June 23, 2011 09:56 — forked from larscwallin/simplx_toplaceholders.php
MODx toPlaceholders wrapper
<?php
/*
Snippet "simplx_toplaceholders"
KISS Snippet which wraps the $modx equivalent, only adds the ability to use JSON input.
Example:
@Mark-H
Mark-H / gist:1136683
Created August 10, 2011 12:26
Requesting some RegEx help! Modifying Textile behavior.
This regex:
$this->urlch = '[\w"$\-_.+!*\'(),";\/?:@=&%#{}|\\^~\[\]`]';
As part of this in PHP:
return preg_replace_callback('/
(?:^|(?<=[\s>.$pnct\(])|([{[])) # $pre
" # start
(' . $this->c . ') # $atts
([^("|\]]+) # $text