You have much redundant code in if and else. I propose to set $content variable in if and extract the whole html::a creation code out of the if.