Skip to content

Instantly share code, notes, and snippets.

View ideesimple's full-sized avatar

Laurent Toulemonde ideesimple

View GitHub Profile
@EVAL return $modx->runSnippet('getAside',array("idRessource" =>"147"));
@ideesimple
ideesimple / gist:725002
Created December 2, 2010 08:51
snippet FirstChildRedirect
$docid = (isset($docid))? $docid: $modx->documentIdentifier;
$children= $modx->getActiveChildren($docid, 'menuindex', 'ASC');
if (!$children === false) {
$firstChild= $children[0];
$firstChildUrl= $modx->makeUrl($firstChild['id']);
} else {
$firstChildUrl= $modx->makeUrl($modx->config['site_start']);
}
return $modx->sendRedirect($firstChildUrl);
@ideesimple
ideesimple / gist:725005
Created December 2, 2010 08:52
Multiplier prix par un nombre via snippet
<?php
//[[*Price:mpyfs=`1.196`]]
$output = '';
if (!empty($input) && is_numeric($input) && !empty($options) && is_numeric($options)) {
/* Multiply & Round the Float to 2 Digits */
$output = round($input * $options, 2);
}
else
@ideesimple
ideesimple / gist:725006
Created December 2, 2010 08:53
Revolution Performance
<br /><!--MySQL: [^qt^], [^q^] request(s), PHP: [^p^], total: [^t^], document retrieved from [^s^]. -->
@ideesimple
ideesimple / gist:725008
Created December 2, 2010 08:55
stylesheets for only 1 resource (in snippet)
<?php
$modx->regClientCSS('path/to/css/file');
$modx->regClientStartupScript('path/to/js/file');
@ideesimple
ideesimple / gist:725010
Created December 2, 2010 08:58
show chunk if parent is:
$current_docid = $modx->resource->get('parent');
$output ='';
if($current_docid ==8){
$output = $modx->getChunk('this_chunk');
}
elseif($current_docid ==9){
$output = $modx->getChunk('this_chunk');
}
@ideesimple
ideesimple / gist:740511
Created December 14, 2010 14:46
récupère la position d'une ressource ainsi que le nombre de ressource de son parent
<?php
$count = 0;
$IdAvant='';
$IdApres='';
$position='';
$criteria = array(
'parent' => $parent,
'deleted' => false,
'published' => true,
);
@ideesimple
ideesimple / gist:740570
Created December 14, 2010 15:26
return single value results via xPDO
<?php
$stmt = $modx->query("SELECT MAX(id) FROM {$modx->getTableName('modResource')}");
$maxId = (integer) $stmt->fetch(PDO::FETCH_COLUMN);
$stmt->closeCursor();
?>
@ideesimple
ideesimple / var_dump
Created December 16, 2010 16:20
afficher valeur dans un tableau via javascript
function var_dump(obj) {
if(typeof obj == "object") {
return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
} else {
return "Type: "+typeof(obj)+"\nValue: "+obj;
}
}
@ideesimple
ideesimple / gist:751361
Created December 22, 2010 10:36
différent chunk ou bout de code selon l'id
[[*id:is=`1`:then=`[[$chunk1]]`:else=`[[$chunk2]]`]]
[[*id:is=`1`:then=`ton code`:else=`ton autre code`]]