1

Please someone tell me where I'm going wrong with this. I have a Matrix field called Page Builder (pageBuilder) and have different matrix blocks for outputting information in different ways.

This code in the entry template works fine for every field except for the one called Placement (placement) which is a position select field. I can't for the life of me get it to output anything at all :-(

Please tell me where I'm going wrong on this one as I'm sure it's going to be something stupid with my code syntax somewhere but just can't tell where for the life of me!!

{% for block in entry.pageBuilder %}

{% switch block.type %}

    {% case "textBlock" %}

        {{ block.text }}

    {% case "callToAction" %}

        <h3>{{ block.blockColour }}</h3> {{ block.text }}

    {% case "sectionBlock" %}

        {{ block.text}}

    {% case "threeColumn" %}

        {{ block.column1 }}
        {{ block.column2 }}
        {{ block.column3 }}

    {% case "smallColumnLargeColumn" %}

        {# CAN'T GET THIS NEXT BIT WORKING #}
        {% switch block.placement %}
                {% case "left" %}
                <p>Code to output if left</p>
                {% case "right" %}
                <p>Code to output if right</p>
        {% endswitch %}
        {# ----------------------------------- #}

        {{ block.column1 }}
        {{ block.column2 }}

{% endswitch %}
{% endfor %}
2

If you're looking to just output the value of the PositionSelect field, it's block.placement.

See here for more info: http://buildwithcraft.com/docs/position-select-fields#templating

| improve this answer | |
  • Hi Brad. Thanks. I have actually tried that too and it's not working. Sorry about the code above, I'd momentarily converted the field into a drop-down when it wasn't working in order to see if that would work and it did but still can't get a position field to work unfortunately. – Mark Bowen Jun 19 '15 at 6:35
  • Are you sure it actually has a value selected? – Brad Bell Jun 19 '15 at 17:11
  • Hmm is it possible to not have one selected? It's set to left currently although I didn't actually select that it was what was set out of the box so to speak. I did try changing it from left to right a couple of times though to see if that would help as some other CMSs would sometimes not set a value for a field if you added the field in after the entry had been created and didn't resave the entry. That wasn't it though. Going to have to try this out on a different template severely cut back in terms of code and see what happens. Seems very odd at the moment though. – Mark Bowen Jun 19 '15 at 17:14
  • Brad. Some info for you, and this one is strange. If I take out the {% switch %} tag and just output {{ block.placement }} then it spits out what it should spit out and I get left or right depending on what was selected for each block. That's all great however it seems as though I just can't get a switch tag to work with the position field. Does it work fine on anyone else's installs? It's definitely spitting out a value for that {{ block.placement }} variable but just won't work at all inside a switch tag. Please someone let me know this isn't me as I feel I'm going mad!! ;-) – Mark Bowen Jun 19 '15 at 18:12
  • Agggh!! My original code doesn't actually show fully what I'm doing. I don't actually need the value of the {{ block.placement }} variable. What I'm trying to do is to use that within a switch to check what the value is and then spit out some code based upon that. I'll update the code above to reflect what I'm trying to do but I'm guessing that perhaps a switch can't go within a switch? If so what's my next option? – Mark Bowen Jun 19 '15 at 18:31

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.