3

Does Craft have an answer to ExpressionEngine's {switch} tag?

{switch="classOne|classTwo|classThree"}
5

Yes, you can do the same in Craft using Twig's cycle function:

{% set myClasses = ['classOne', 'classTwo', 'classThree'] %}

{% for entry in entries %}
    {{ cycle(myClasses, loop.index0) }}
{% endfor %}
0

From the documentation site

{% switch matrixBlock.type %}

    {% case "text" %}

        {{ matrixBlock.textField | markdown }}

    {% case "image" %}

        {{ matrixBlock.image[0].getImg() }}

    {% default %}

        <p>A font walks into a bar.</p>
        <p>The bartender says, “Hey, we don’t serve your type in here!”</p>

{% endswitch %}

http://buildwithcraft.com/docs/templating/switch

  • 1
    Despite the fact that the names are the same, those two functions do very different things. To be fair, EE is grossly misusing the switch terminology. – Lindsey D Jan 21 '15 at 17:50

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.