Skip to content

Instantly share code, notes, and snippets.

@jenswittmann
Last active September 4, 2025 11:37
Show Gist options
  • Select an option

  • Save jenswittmann/773a580327ce54b4b73f8a808cc00a0b to your computer and use it in GitHub Desktop.

Select an option

Save jenswittmann/773a580327ce54b4b73f8a808cc00a0b to your computer and use it in GitHub Desktop.
Use Fenom via pdoTools in ContentBlocks

Use this Snippet to render Fenom Syntax in MODX ContentBlocks

Unlike the @PDO_FILE approach, this approach eliminates the need to save a resource during development. Additionally, all values are not stored in MODX chunk properties within the resource itself, which can cause issues when using a symbol such as ` in your content.

  1. Add a Snippet called pdoChunk and place the code pdochunk.snippet.php.
  2. Create a ContentBlocks field and use the code ContentBlocks field template for the template value.
  3. Make sure you have set the System Setting pdotools_elements_path to the correct path.
[[pdoChunk?
&file=`contentblocks/your-chunk-name.chunk.tpl`
&field=`[[+field]]`
&field_type_idx=`[[+field_type_idx]]` ]]
<?php
$file = $modx->getOption("file", $scriptProperties);
$field = $modx->getOption("field", $scriptProperties);
$fieldTypeIdx = $modx->getOption("field_type_idx", $scriptProperties);
$fieldContent = [];
$pdo = $modx->getService('pdoTools');
$cbGetFieldContent = $modx->runSnippet('cbGetFieldContent', [
'field' => $field,
'offset' => $fieldTypeIdx,
'limit' => 1,
'returnAsJSON' => true,
]);
$fieldContent = $modx->fromJSON($cbGetFieldContent);
return $pdo->getChunk('@FILE ' . $file, [
'fieldContent' => $fieldContent[0],
'scriptProperties' => $scriptProperties
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment