Live This site runs Joomla 6.1.2
JoomClub

News, security and craft for the Joomla ecosystem

Extensions

WT Layout Select brings PHP layout selection to Joomla fields

WT Layout Select is a Joomla custom-field plugin that lets editors choose a PHP layout from configured folders, while accounting for overrides in the active site template. The field stores the selected layout and base path as JSON and…

The plugin scans specified directories for PHP layouts and presents the available options in a dropdown. It also checks the corresponding override locations under /templates/<template>/html/..., allowing a site’s active template overrides to be included in the selection process.

When a layout is selected, the field’s rawvalue contains JSON with the layout and basePath properties. Its computed value contains a layout_id, which can be used to identify the selected layout.

Rendering a selected layout

A template override can read the field value and pass the stored layout data to LayoutHelper::render():

<?php
use Joomla\CMS\Layout\LayoutHelper;

$field = $this->item->jcfields[14] ?? null;

if ($field && !empty($field->rawvalue)) {
    $raw = json_decode($field->rawvalue);

    if (!empty($raw->layout) && !empty($raw->basePath)) {
        echo LayoutHelper::render($raw->layout, ['item' => $this->item], $raw->basePath);
    }
}

For example, a layout stored at JPATH_ROOT/layouts/com_content/article/sections/pricelist.php can be addressed as com_content.article.sections.pricelist. The approach can be used for article sections, contact cards, category and list components, module-position areas, and reusable layout blocks for Joomla landing pages.