Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi all,
<% if(umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("aliasName").ToString()!=""){ %>
Why does this ALWAYS evaluate to true, even if there's no data in the variable aliasName?
How can I check for th presence / state of a document value in templates?
Hi Matt,
To get the Value of a property you need :
umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("aliasName").Value.ToString()
(bear in mind the Value can be a null, in which case the ToString() will error - I use some helper methods to prevent having to do these null checks each time)
HTH,
Hendy
eg.
<%@ Import namespace="umbraco.presentation.nodeFactory" %>
<script runat="server"> public static string GetNodeProperty(string propertyName) { return GetNodeProperty(Node.GetCurrent(), propertyName); } public static string GetNodeProperty(int nodeId, string propertyName) { return GetNodeProperty(new Node(nodeId), propertyName); } public static string GetNodeProperty(Node node, string propertyName) { string propertyValue = string.Empty; if (node != null && node.GetProperty(propertyName) != null) { propertyValue = node.GetProperty(propertyName).Value; } return propertyValue; }</script>
<% if (GetNodeProperty("aliasName") != string.Empty) {%>...<%}%>
Thanks! Works perfectly. :D
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Conditional section in a template
Hi all,
<% if(umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("aliasName").ToString()!=""){ %>
Why does this ALWAYS evaluate to true, even if there's no data in the variable aliasName?
How can I check for th presence / state of a document value in templates?
Hi Matt,
To get the Value of a property you need :
umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("aliasName").Value.ToString()
(bear in mind the Value can be a null, in which case the ToString() will error - I use some helper methods to prevent having to do these null checks each time)
HTH,
Hendy
eg.
Thanks! Works perfectly. :D
is working on a reply...