Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Display link only if link URL not empty

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1473 Views
  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Display link only if link URL not empty Link to this post

    If (( $LinkURL is not empty ) and ( $LinkText is not empty )) then I want to display the link with the link text inside.

    <a href="$LinkURL.ATT" title="$LinkText.ATT">$LinkText.ATT</a>

    Else if (( $LinkURL is empty ) and ( $LinkText is not empty )) then I want to display the link text but I don't want it to be a link.

    Else if (( $LinkURL is empty and $LinkText is empty )) then I don't want to display anything.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Display link only if link URL not empty Link to this post

    There are 2 ways of doing this, you can either use the build in template conditionals or you can write a function of your own to test which are empty and return the appropriate values.

    To do it in the template you can do this:

    <% if LinkText %>
    <% if LinkURL %>
    <a href="$LinkURL.ATT" title="$LinkText.ATT">$LinkText.ATT</a>
    <% else %>
    $LinkText
    <% end_if %>
    <% end_if %>

    Not particularly pretty but will do the job.

    1473 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.