I'm trying to show content in my masterpage depending on a true/false property on my document type. I'm using inline C# and i know this looks like it would be easier to solve with a macro but with the full context it's not.
I got this so far.
<% if (umbraco.library.GetXmlNodeById("0").GetProperty("protectContent").Value.ToString() == "1") {%>
<pre>Showing protected content</pre>
<%}%>
and umbraco.library.GetXmlNodeById("0") is instead of $currentPage
Update:
This is the error message i recieve when running this code:
Compiler Error Message: CS1061: 'System.Xml.XPath.XPathNodeIterator' does not contain a definition for 'GetProperty' and no extension method 'GetProperty' accepting a first argument of type 'System.Xml.XPath.XPathNodeIterator' could be found (are you missing a using directive or an assembly reference?)
I think this should be solved by creating a macro, but I see you're already aware of this ;-)
The error in your code is exactly what your error messages says: the System.Xml.XPath.XPathNodeIterator doesn't contains a method with the name "GetProperty".
The return type of the umbraco.library.GetXmlNodeById() method is an XPathNodeIterator. What you'll want is to get a new Node object when in the context of ASP.NET. So, something like this should help you out:
<%
var node = new Node(1234);
if(node.GetProperty("protectedContent").Value.ToString().Equals("1")
{
//Your output here
}
%>
Without knowing anything about the context of this issue, I guess youøre already aware of the procedure of protecting content from members? :-)
Get property in inline C#
I'm trying to show content in my masterpage depending on a true/false property on my document type. I'm using inline C# and i know this looks like it would be easier to solve with a macro but with the full context it's not.
I got this so far.
and
umbraco.library.GetXmlNodeById("0")
is instead of$currentPage
Update: This is the error message i recieve when running this code:
Hi, what data are you trying to get? And why are you using GetXmlNodeById
Charlie :)
Hi Johan,
I think this should be solved by creating a macro, but I see you're already aware of this ;-)
The error in your code is exactly what your error messages says: the System.Xml.XPath.XPathNodeIterator doesn't contains a method with the name "GetProperty".
The return type of the
umbraco.library.GetXmlNodeById()
method is an XPathNodeIterator. What you'll want is to get a newNode
object when in the context of ASP.NET. So, something like this should help you out:Without knowing anything about the context of this issue, I guess youøre already aware of the procedure of protecting content from members? :-)
/ Bo
Thanks Bo! The final code looks like this:
I got the members part under control, thanx :)
No problem :-) happy to help.
is working on a reply...