1

I'm showing entries on a page. Depending on the value of the field postAspectRatio, I would like the layout of this shown entry to change just slightly and thus requiring it's own unique markup.

I've tried to do this using what I know about twig IF syntax but it's not working.

Any help?

{% block content %}

{% for entry in craft.entries.section('projects').order('postDate asc').limit(500).find() %}

        {% if entry.postAspectRatio == 'Portrait' %}

        <div class="title portrait">
            <a href="{{ entry.url }}">
                <p><span>{{ entry.studio }}</span>{{ entry.title }}</p>
            </a>
        </div>

        {% endif %}

        {% if entry.postAspectRatio == 'Landscape' %}

        <div class="title landscape">
            <a href="{{ entry.url }}">
                <p><span>{{ entry.studio }}</span>{{ entry.title }}</p>
            </a>
        </div>

        {% endif %}

{% endfor %}

{% endblock %}
  • 1
    Your syntax is right. What type of field is postAspectRatio? – carlcs Dec 13 '14 at 7:59
  • 1
    Test the output with {{ entry.postAspectRatio }}. – carlcs Dec 13 '14 at 8:04
1

Your if statements looks correct. You might check that you are testing the value vs. the name (i.e. 'Portrait' vs 'portrait') or printing out the value (using {{ entry.postAspectRatio }}) so you can see the output. Also, a 'dryer' way to write this might be:

{% block content %}

    {% for entry in craft.entries.section('projects').order('postDate asc').limit(500).find() %}

        <div class="title {{ entry.postAspectRatio|lower }}">
            <a href="{{ entry.url }}">
                <p><span>{{ entry.studio }}</span>{{ entry.title }}</p>
            </a>
        </div>

    {% endfor %}

{% endblock %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.