Advanced Custom Fields

Flexible Content

Flexible content is usually rendered with set partials.

Flexible Content Loop#

phpresources/views/front-page.php
{{ sections }}  {{ partial src="sets.home.{set}" }}{{ else }}  <p>No sections.</p>{{ /sections }}

TemplateX uses the current row layout to replace {set}.

If the row layout is hero, the example above looks for a matching partial such as:

            • hero.php

Set Partials#

Set partials use the current ACF row as their context:

phpresources/views/partials/sets/home/hero.php
<section data-set="{{ set }}">  <h2>{{ title }}</h2>  <img src="{{ image }}" alt="{{ image.alt }}"></section>

Inside a set partial, {{ set }} is the current row layout, and fields such as {{ title }} and {{ image }} come from the flexible content row.

Nested Flexible Content#

Nested flexible content inside a set partial stays in the current row context:

phpresources/views/partials/sets/home/cards.php
{{ cards }}  {{ partial src="sets.cards.{set}" }}{{ /cards }}

Use this when flexible content rows contain smaller flexible content areas.