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, biapar, Willr, Ingo, swaiba, simon_w

Display link only if link URL not empty


Reply


2 Posts   1555 Views

Avatar
DeklinKelly

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.

Avatar
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 %>
$LinkText
<% end_if %>
<% end_if %>

Not particularly pretty but will do the job.