For the complete documentation index, see llms.txt. This page is also available as Markdown.

Smart PHP templates

Layout and Post Selection templates support vanilla PHP as a template engine. These templates are executed with eval, so you can use any WordPress or PHP function inside them.

The default template uses built-in PHP short opening tags and alternative control syntax to make the template clearer and less verbose:

<? foreach ($categories["value"] as $index => $term_item): ?>
    <a target="<?= esc_html($term_item["target"]); ?>" class="acf-view__categories-link" href="<?= esc_html($term_item["value"]); ?>">
        <?= esc_html($term_item["linkLabel"] ?: $term_item["title"]); ?>
    </a>
<? endforeach; ?>

The classic one for comparison:

<?php foreach ($categories["value"] as $index => $term_item) { ?>
    <a target="<?php echo esc_html($term_item["target"]); ?>" class="acf-view__categories-link" href="<?php echo esc_html($term_item["value"]); ?>">
        <?php echo esc_html($term_item["linkLabel"] ?: $term_item["title"]); ?>
    </a>
<?php } ?>

You're totally free to use whatever version you prefer, or even mix them.

Don't sacrifice the shorter alternative only for compatibility reasons. Advanced Views automatically replaces short tags with their full aliases before execution, so template rendering is completely independent of the short tag ini-setting.

Last updated