Blog Sections Open

Getting URLs for All Child Resources Inside a Container

Generate a full list of child resource URLs in Evolution CMS, including unpublished descendants when you need them.

Sometimes you need the full URL list for a section, not just the visible menu items. Export tasks, validation scripts, and migration helpers often need every child resource under a container, including unpublished pages.

The use case is simple, but very practical. The easiest modern approach is to query the descendants of a container and then turn each document into a URL with the core URL generator.

Simple example

use EvolutionCMS\Models\SiteContent;

$docs = SiteContent::descendantsOf($containerId)
    ->where('deleted', 0)
    ->get();

$urls = $docs->map(function ($doc) use ($modx) {
    return $modx->makeUrl($doc->id, '', '', 'full');
})->all();

Including unpublished resources

Do not call active() if you need unpublished documents in the result. The moment you add the active scope, unpublished resources disappear from the list. For migration and QA utilities you usually want deleted resources excluded, but unpublished resources included.

When a flat list is enough

A plain array of URLs is useful for exports, feed generation, QA crawls, and cache warmers. If you also need hierarchy information, keep the depth or parent ID in the same result set instead of throwing it away too early.

Newer post

Adding Google reCAPTCHA to a Registration Form in MODX Evolution

A practical way to protect AJAX-driven MODX Evolution registration forms from bot signups and fake email abuse.

Older post

Logging Out All Web Users After a Security Event

An operational note on forcing all web users to sign in again when a site experiences a security issue or a session reset is needed.