Blog Sections Open
Using the First Content Image as a News Preview in Evolution CMS
A practical snippet pattern for deriving a preview image from article content when editors skip the dedicated image TV.
One very common editorial shortcut is to skip the dedicated preview-image TV and place the first image directly inside the article body. This snippet was written to turn that habit into something usable in listings.
What the snippet does
It first checks whether a dedicated image TV has a value. If not, it scans the resource content and returns the first <img> source it finds.
<?php
$image = isset($image) ? $image : '';
$results = $modx->getDocument($id, 'content');
$content = $results['content'];
$img = $modx->getTemplateVarOutput($image, $id);
$tvimage = $img[$image];
preg_match_all('/<img.+src=['"]([^'"]+)['"].*>/i', $content, $matches);
$first_img = $matches[1][0];
if (!empty($tvimage)) {
return $tvimage;
}
return $first_img;
Typical listing usage
<img src="[[contentImg? &id=`[+id+]` &image=`image`]]" alt="[+pagetitle+]" />
It is not a complete media strategy, but it is a useful fallback pattern when editorial discipline is inconsistent and you still need the list view to look respectable.
Moving the Evolution CMS Manager Without Patching Core Blindly
A hardening-oriented guide to changing the manager path, understanding why it is not fully abstracted in core, and planning the move carefully.
Skipping a Snippet on One Page Without PHx
A lightweight alternative to PHx conditions when you need a snippet to stop executing on one specific resource.