I've created a custom module citation for academic references. Citations have, among other things, a title and an optional articleURL to link to the original article.
Is there a way for me to write the widget template so that, if the URL is not blank, render it as a link? With apologies for my PHP style pseudocode (new to sitefinity/.net), what I have in my head is something like:
if (notEmpty('articleURL')) {
<a href="<%# Eval("articleURL")%>"><%# Eval("Title")%></a>
} else {
<%# Eval("Title")%>}
Ideally, I'd like to be able to do this through the online widget editor, rather than an external file.
I know I answered this on the Sitefinity forums where you cross-posted, so I'm repeating the solution here in case anyone else is looking here for this question.
by default, the built-in widget template editor will strip any server side code so this approach unfortunately won't work.
However, I believe there are two ways to achieve the desired result.
You might be able to use the tertiary operator to hide a value, such as:
<%# Eval("Foo") == null ? "" : Eval("Foo") %>
Alternatively, you can map the widget template to an external file. Using an external template file will not strip the code, and you have full control to render the content however you wish.
For more information on mapping templates, take a look at this post: Mapping External Templates for Sitefinity 4 Widgets
hope this is helpful!