Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Mark-H/1042279 to your computer and use it in GitHub Desktop.
Save Mark-H/1042279 to your computer and use it in GitHub Desktop.
MODx toPlaceholders wrapper
<?php
/*
Snippet "simplx_toplaceholders"
KISS Snippet which wraps the $modx equivalent, only adds the ability to use JSON input.
Example:
[[!simplx_toplaceholders?&subject=`{"typename":"person","name":"Joe Snippetson","address":{"street":"Next Street 5","zip":"55 555","city":"Utopia"}}`]]
<br/>Name:<br/>
[[!+name]]
<br/>Address:<br/>
[[!+address.street]]
<br/>
[[!+address.zip]] [[!+address.city]]
---------------------------------------------------------------------------
The subject parameter could of course be any Chunk or Snippet or String :)
*/
if(!$subject){
return '';
}
$subject = $modx->fromJSON($subject,true);
$prefix = isset($prefix) ? $prefix : '';
$separator = isset($separator) ? $separator : '.';
$modx->toPlaceholders($subject,$prefix,$separator);
return;
@Mark-H
Copy link
Author

Mark-H commented Jun 23, 2011

See my fork for a fix in your example.. also changed jsondecode to the modx equivalent (fromJSON) which works even if the server doesn't support json* functions :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment