1

I have a dropdown Matrix block and need to check whether a selected value is either one or another. If either value is selected I want to display some text on the front end. At the moment I have {% if block.wellFormattedContent =='toBeActioned' OR block.wellFormattedContent =='partiallyActioned' %} but it errors. Hopefully you can see what i'm trying to do.

Thanks

Martin

  • Try or in lowercase. You can learn more about the templating language here twig.sensiolabs.org/documentation – Ben Fleming Jan 20 '16 at 10:59
  • Also, if you haven't done so already, turn on dev mode in your config file (add the line 'devMode' => true,), it'll give you much more descriptive errors making debugging so much easier! – Ben Fleming Jan 20 '16 at 11:02
2

As already noted by @Benjammin' in the comments, the or operator has to be lowercase. See Logic Expressions in the Twig docs:

Operators are case sensitive.

You also have to get the dropdown value explicitly by accessing its value property.

{% if block.wellFormattedContent.value == 'toBeActioned' or block.wellFormattedContent.value == 'partiallyActioned' %}

The short syntax {{ block.wellFormattedContent }} (which internally uses the field's toString() magic method) causes problems within Twig conditionals. You can probably also get around this issue by wrapping it in curly braces.

{% if (block.wellFormattedContent) == 'toBeActioned' or (block.wellFormattedContent) == 'partiallyActioned' %}
|improve this answer|||||
  • Thanks Carl (again) :D - Should also note Benjammin point that the OR should be lowercase. – Martin Jan 20 '16 at 11:43
  • Good to know, I thought it doesn't matter. Thanks @Martin and @Benjammin! – carlcs Jan 20 '16 at 12:33

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.