Skip to documentation content

Why Us Section

All complete examples

Render a reusable Why Us section from a repeating fieldset, passing each child custom object to a focused partial.

What this example teaches

  • Guard an optional repeating fieldset before rendering its content
  • Iterate the fieldset as child custom objects with named child fields
  • Pass each child custom object to a focused rendering partial
  • Keep custom fields on the template that owns them

View this pattern on the live demo site

Files

Proof/benefits band used on the home landing.

Liquid
{% comment %}
	Displays a "Why Us" section with intro text, multiple reasons, and a conclusion - all optional
	Inputs:
		section_class
		section_id
	Custom Fields:
		whyus_title
		whyus_subtitle
		whyus_intro
		whyus_reasons - repeating fieldset; each child object has title, image, description, alignment, and layout
		whyus_conclusion

	Outputs:
		section_rendered - true when this section outputs markup, false otherwise
{% endcomment -%}
<section{% if section_class %} class="{{ section_class }}"{% endif %}{% if section_id %} id="{{ section_id }}"{% endif %}>
	<div class="container">
		{%- var headinglevel = headinglevel %}{% comment %}Copy to current scope{% endcomment -%}
		{%- include "/common/_title_with_subtitle.liquid" title:entity.whyus_title subtitle:entity.whyus_subtitle postincrement_headinglevel:true title_classname:'text-center' subtitle_classname:'text-center' -%}

		{%- if entity.whyus_intro.is_valid -%}
			<div class="lead text-center mx-auto mb-5" style="max-width: 42rem;">{{entity.whyus_intro}}</div>
		{%- endif -%}

		{%- if entity.whyus_reasons.is_valid -%}
			<div class="row g-4">
				{%- for reason in entity.whyus_reasons -%}
					<div class="col-md-4">
						<div class="card h-100 border-0 shadow-sm text-bg-light">
							<div class="card-body p-4 text-center">
								{%- include "/partials/_why_us_reason.liquid" reason:reason -%}
							</div>
						</div>
					</div>
				{%- endfor -%}
			</div>
		{%- endif -%}

		{%- if entity.whyus_conclusion.is_valid -%}
			<div class="text-center mt-5 mx-auto" style="max-width: 42rem;">{{entity.whyus_conclusion}}</div>
		{%- endif -%}
	</div>
</section>
{%- set section_rendered = true -%}