This next part is a bit of neatness from ruby/rails - there is a link_to_if that you can use.

http://api.rubyonrails.org/v3.2.0/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to_if

So I believe the <a href=....></a> becomes:
<%= link_to_if(url, urltext, url) %>