Setting placeholder via simple snippet in MODX Evo

How to set placeholder in MODX Evo.

It's not often situation but sometimes there is a need to set up your own placeholder. For example I needed to do this when I wanted to process data given to PHx (in this situation PHx was trimming HTML tags and shortening content). PHx refused to process data retrieved from snippet. To solve this problem I've tried to give PHx placeholder with the same data. It worked :)


Our snippet is going to retrieve data from any TV of specified document. Snippet name "ph".

// Setting placeholder with any document TV on page
// Usage example: [ [ ph?tv='id'&id='346'&ph='my_placeholder_name' ] ]
// By: Piotr Matysiak /

if($method=='get'){$id = $_GET['id'];}
$output = $modx->getTemplateVarOutput(array("$tv"),$docid="$id",$published=1);
$output = $output[''.$tv.''];
$modx->setPlaceholder($ph, $output );

Usage example

[ [ ph?tv='pagetitle'&id='56'&ph='myPh' ] ]

This will set placeholder named "myPh" which will contain page title of document with id 56. We can display it content by including [ + myPh + ]


  • tv - name of Template Variable we want to retrieve
  • id - id of document with TV
  • ph - our placeholder name
Tags: code, evo, modx, php, snippet