Banging my head on this one and have not been able to come up with a solution to this. I'm wanting to create a default template for all single entries that checks for all of the fields I have created if they exist and the position in that section.
This template would have all code for all possible field types. So far this doesn't work the way I was hoping it would as it renders the page based on the order of the code in the template. So if a client adds a new field to a section it doesn't matter what order they put the field in the list of fields, in the end it is determined by where the code to render that field is in the template.
I have developed with wordpress, acf, and visual page builders where you can drag drop elements into different positions which are just shortcodes but the page ends up rendering based on the position of the elements "shortcodes".
Is this at all possible? Here is some examples of some code in said template...
<!-- Testimonials Block -->
{% if entry.testimonials|length %}
<div class="container-fluid add-top">
<div class="row">
<div class="text-center testimonials">
{% for block in entry.testimonials %}
{% if block.type == "testimonial" %}
{% set image = block.image.first() %}
<blockquote class="blockquote-unstyled" style="display:none;">
<footer class="text-uppercase">
<span title="Source Title">{{block.sourceTitle}}</span>
</footer>
<p class="lead">“{{block.lead}}”</p>
</blockquote>
{% endif %}
{% endfor %}
<div class="list-inline">
{% for block in entry.testimonials %}
{% if block.type == "testimonial" %}
{% set image = block.image.first() %}
<li><img class="img-responsive img-circle" alt="Profile" src="{{ image.getUrl('testimonials') }}" width="{{ image.getWidth('testimonials') }}" height="{{ image.getHeight('testimonials') }}"/></li>
{% endif %}
{% endfor %}
</div>
</div>
</div>
</div>
{% endif %}
<!-- Impact Statement -->
{% if entry.impactStatement|length %}
{% for block in entry.impactStatement %}
{% if block.type == "impactStatement" %}
<div class="container-fluid add-top">
<div class="row">
<div class="text-center impact-highlight">
<p>{{block.heading}}</p>
</div>
</div>
</div>
{% endif %}
{% endfor %}
{% endif %}
<!-- Large Headline Blocks -->
{% if entry.largeHeadline|length %}
<div class="container-fluid add-top">
<div class="row">
{% for block in entry.largeHeadline %}
{% if block.type == "headline" %}
{% set image = block.image.first() %}
<div class="col-sm-6 col-md-10 col-md-push-1 add-top">
<div class="row">
<div class="col-sm-6 hidden-xs {{block.imagePosition}}">
<!-- Img Logo -->
<img src="{{image.url}}"/>
</div>
<div class="col-sm-6">
<h3 class="remove-top">{{block.heading}}</h3>
<small>{{block.paragraph}}</small>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
<hr class="add-top">
</div>
{% endif %}
As you can see this is just three field types but I have a lot. But for this example the template has them in this order.
Testimonials Matrix Field
Impact Statement
Large Headline
If I move impact statement in the section above testimonials, that has no relation on where that impact statement gets rendered in the entry...
I also tried to do ifelse thinking it would loop through the template outputting the blocks in the order they are in the section for that single if they exist. But this just outputs the testimonials block and stops haha.
{% if entry.testimonials|length %}
//Block Code
{% elseif entry.testimonials|length %}
//Block Code
{% elseif entry.testimonials|length %}
//Block Code
{% endif %}
I thought one way to solve it would just be to have one matrix field with all of the possible fields as a block with each field in that block, but then I think I run into issues wrapping each element in a container as for each block I end up outputting a container so they end up nested.
Any solutions or possible tips would be great. Hope this makes sense.