Output modifiers in field template

Hi! Can’t get this output modifiers in a Repeater element to work.
If there is a link set, an a-tag with target should be wrapped, if it’s empty an div tag.

[[+url:!empty=`
    <a href='[[+url]]' target='_blank' class='logo cell medium-3 ratio1-1' data-equalizer-watch>
        [[+logo]]
    </a>
`]]
[[+url:empty=`
    <div class='logo cell small-6 medium-3 Xratio1-1' data-equalizer-watch>
        [[+logo]]
    </div>
`]]

Currently the html-output is like this:

<div class="logos grid-x grid-margin-x align-middle" data-equalizer="" data-equalize-on="medium" data-resize="mkhgn8-eq" data-mutate="03dcja-eq" data-n="b1p0z1-n" data-events="resize">
    https://www.my-domain.tld/
    <a href="https://www..my-domain.tld/" target="_blank" class="logo cell medium-3 ratio1-1" data-equalizer-watch="" style="height: auto;">
        <img src="/assets/media/crops/standard.fab7edf7.logo_xyz_scaled.jpg" alt="" class="logo-img" width="182" height="53">
    </a>
https://domain.com/
    <a href="https://domain.com/" target="_blank" class="logo cell medium-3 ratio1-1" data-equalizer-watch="" style="height: auto;">
        <img src="/assets/media/crops/standard.6ef056de.logo_zz.jpg" alt="" class="logo-img" width="182" height="68">
    </a>
https://www.domain.tld/
    <a href="https://www.domain.tld/" target="_blank" class="logo cell medium-3 ratio1-1" data-equalizer-watch="" style="height: auto;">
        <img src="/assets/media/crops/standard.9eef4695.logo_test400x103.png" alt="" class="logo-img" width="182" height="52">
    </a>
</div>

Do I miss something? Thank’s in advance for your time!

Sorry for not responding sooner. It looks like it should work to me, but maybe try this?

[[+url:notempty=`
    <a href='[[+url]]' target='_blank' class='logo cell medium-3 ratio1-1' data-equalizer-watch>
        [[+logo]]
    </a>
`:default=`
    <div class='logo cell small-6 medium-3 Xratio1-1' data-equalizer-watch>
        [[+logo]]
    </div>
`]]

Are you on MODX 2 or 3?

Hi Mark,

thanks for taking time. Your code works! :grinning:
Why does mine does not work? I’m still on MODX 2.

Greetings, Sebastian

I think it doesn’t work with your setup because of this:

If the url is empty, it will render the logo without link

But if the url is not empty, it will still render the value of the url because the url placeholder value is not changed by another output modifier.

In my example, it is chained. If the url is not empty, it will render the link with logo. But the default clause makes sure that if the url is empty, it will render the logo in the div. So there’s both the “if” and “else” there, while your code misses additional behavior for the “else”.

1 Like

Ah… this makes sense. Thanks for your explanation, Mark!

1 Like