Blog Sections Open
Using DocLister prepare to Build Image Paths from Resource IDs
A practical DocLister pattern for computing per-item image paths inside prepare when files follow an id-based directory layout.
DocLister is often used to render catalogs where the image path is not stored directly in the resource. Instead, files live in a predictable folder such as /images/{id}/, and the output layer must derive the file path for each item.
The problem
You can access placeholder values inside the item template, but sometimes you need to transform them first and expose a ready-to-use path. That is where prepare becomes useful.
Typical storage rule
/images/123/main.jpg
/images/124/main.jpg
Prepare example
&prepare=`catalogPrepare`
function catalogPrepare($data, $modx, $DL, $e) {
$id = $data['id'];
$data['catalog_image'] = "/images/{$id}/main.jpg";
return $data;
}
Using the prepared field in the template
<img src="[+catalog_image+]" alt="[+pagetitle+]">
Why this is better than hardcoding logic in the chunk
- the chunk stays readable
- the path-building rule stays in one place
- you can add file existence checks or fallback logic later
- the same prepare function can be reused in multiple listings
If your catalog relies on consistent folder naming, prepare is one of the cleanest ways to turn raw resource data into front-end-ready image paths.
Counting Resources by Multi-Value TV Selections in Evolution CMS
A practical strategy for counting resources that match specific values inside a multi-value TV field.
Getting PageBuilder Block Fields to Appear in Evolution CMS
How to reason about PageBuilder setups where the block tab exists but no editable fields appear in Evolution CMS.