Hi all, I’m looking for the most DRY solution for coding a template with some specific functionality.
The Scenario
The first channel is “Private Water Supplies” - there’s an entry for each type of customer, giving a general description of services. The entries are:
Domestic
Agriculture
Industry
Property Development
Hotels
Offices
Government
Sports Clubs
Education
The second channel is “Testimonials” - entries are categorised by type of customer, the categories match the Private Water Supply entries, i.e.:
Domestic
Agriculture
Industry
Property Development
Hotels
Offices
Government
Sports Clubs
Education
My Private Water Supplies template needs to pull one random testimonial for each entry from the Testimonial channel entries with the appropriate category. I.e.:
private-water-supplies/domestic displays one testimonial at chosen at random from all testimonials in the domestic category; private-water-supplies/education displays one testimonial at chosen at random from all testimonials in the education category; etc.
Current Solution
My Private Water Supplies template currently uses the following code for the domestic testimonial category:
{if segment_2 == 'domestic'}
<blockquote class="testimonial">
{exp:channel:entries channel="testimonials" disable="member_data|pagination" limit="1" category="3" orderby="random" dynamic="no"}
{testimonial_main_content}
<h6 class="caption">{if testimonial_client_name}{testimonial_client_name}, {/if}{if testimonial_position}{testimonial_position}, {/if}{if testimonial_company}{testimonial_company}, {/if}{if testimonia_location}{testimonia_location}{/if}</h6>
{/exp:channel:entries}
</blockquote>
{/if}This code will have to be repeated using {if:ifelse} statements for each of the other 8 testimonial categories, changing the
category="3"for each category.
Question
Is there a way I can automate the {if} statement so that testimonials in the appropriate category are displayed based on the segment_2 value - or maybe there’s another way to achieve the same result?
Thanks in advance for any suggestions.