A lot of the template parsing mechanisms, support some sort of conditional wrapping.
For example, if an image exists, include the image, otherwise, don't.
In SilverStripe, I have to check with an if-statement.
Also, an often called feature is the link. If a link exist, wrap the text in an <a> tag, otherwise, just return the link.
Now, it requires <% if $Link %><a href="$Link"><% end_if %>Link text<% if $Link %></a><% end_if %>.
I suggest a <% wrap "a", "Link" %>Link text<% end_wrap %> method, which will do the same, but with less tags/ifs/conditionals.
The function itself, should take the first as the wrapping item, regardless of what it is. The second argument should be what to test for. And, thus, returning a wrapped string, if there is a Link method that returns something useful, otherwise, just return the string.