Conditionally Hide a Link in a Metabox Vioew if the Custom field is empty?

Support MB Views Conditionally Hide a Link in a Metabox Vioew if the Custom field is empty?Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40718
    JBPHJBPH
    Participant

    Hi people!
    Please can someone help me with this code??
    I have a metabox view with a link to "Download Brochure" that I need to conditionally hide if the custom field "{{ post.upload_presentation }}" is empty:

    Here is my view code:

    {% set relationship = attribute( relationships, 'venues-to-galleries' ) %}
    {% for post in relationship.from %}
    <div id="div_block" class="grid-venue-properties">
    {% for clone in post.venue_info_group %}
    <div class="pad--xs grid-venue-properties__item">{{ clone.venue_item }}</div>
    <div class="pad--xs grid-venue-properties__item">{{ clone.item_description }}</div>
    {% endfor %}
    </div>
    <br>
    <a class="ct-link-button download-brochure__btn" href="{{ post.upload_presentation }}" download>Download Brochure</a>
    {% endfor %}

    So I think that this part needs wrapping in some type of if/else code:

    <br>
    <a class="ct-link-button download-brochure__btn" href="{{ post.upload_presentation }}" download>Download Brochure</a>

    Unfortunately I am not a coder so all my atetmpts keeping breaking my site!

    #40722
    PeterPeter
    Moderator

    Hello,

    You can follow the topic below to check if the field is not empty with the Twig code
    https://stackoverflow.com/questions/22968427/check-if-string-variable-is-null-or-empty-or-full-of-white-spaces

    For example:

    {% if post.upload_presentation|trim is not empty %} 
    <a class="ct-link-button download-brochure__btn" href="{{ post.upload_presentation }}" download>Download Brochure</a>
    {% endif %}
    #40724
    JBPHJBPH
    Participant

    That's perfect thanks!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.