Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

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

Display link only if link URL not empty

Go to End

2 Posts   2077 Views


Community Member, 197 Posts

13 May 2009 at 4:14am

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.

Carbon Crayon

Community Member, 598 Posts

13 May 2009 at 10:31pm

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 %>
<% end_if %>
<% end_if %>

Not particularly pretty but will do the job.