The Node class is found in the umbraco.presentation.nodeFactory which is what you should write in your using statement, this namespace is in the core umbraco assembly (umbraco.dll)
The umbraco assembly also contains a library class, that is used a lot in xslt files, and is also availabe for codebehinds, it contains a lot of different static method that can be useful, like the GetItem(string alias) method. This method returns a named attribute or property on the current page (or even another page if you use the GetItem(int nodeId, string alias) overload. With this you can do things like:
using umbraco;
// namespace and class declarations
string title = library.GetItem("title");
I recommend downloading Red Gate's .NET Reflector and use that for opening the umbraco dlls, and check out the code. You can even use it to search for the Node class and find it, once the umbraco.dll is opened.
What is the simplest way to write umbraco items from the code behind ?
Hello,
I've been trying to use a Literal to dynamically change the field of an umbraco item, however it doesn't display.
Liberal.Text = "<umbraco:Item runat=\"server\" field=\"title\" />";
If I do Liberal.Text = "lol"; or even Liberal.Text = "<a href=\"address\">link</a>"; it displays fine, but it doesn't work with the umbraco item.
Putting <umbraco:Item runat="server" field="title" /> in the page also work so the umbraco item is working, the problem is with the liberal.
I would like to change the field string in the code behind depending on the language parameter in the url, with something like:
string str = "title_" + Request.Params.Get("lang");
string txt = "<umbraco:Item ID=\"Item1\" runat=\"server\" field=\"" + str + "\" />";
Liberal.Text = txt;
So I could get field="title_en" or field="title_fr" in the umbraco item.
Does anyone have a simple way to display umbraco items with parameters that you can change in the code behind file of a masterpage ?
Thanks alot in advance
<umbraco:item> is a server side control. same as the Literal control. To set your literals text property, you could do something like this:
Though remember to at least HtmlEncode the QueryString before doing something like that.
Ah, so I can't "echo" a control in a literal ? I get it now why it didn't work.
To try your Node.GetCurrent();
What "using" do I have to reference in the code ?
Also thanks for the help, I'm a computer science student :)
And while I'm at it, putting aside my initial issue with the Liberal,
how do YOU guys render umbraco controls dynamically anyway ?
What's the "pro" way to do it ?
Hello Nick, and welcome to Umbraco
The Node class is found in the umbraco.presentation.nodeFactory which is what you should write in your using statement, this namespace is in the core umbraco assembly (umbraco.dll)
The umbraco assembly also contains a library class, that is used a lot in xslt files, and is also availabe for codebehinds, it contains a lot of different static method that can be useful, like the GetItem(string alias) method. This method returns a named attribute or property on the current page (or even another page if you use the GetItem(int nodeId, string alias) overload. With this you can do things like:
In a cs-codebehind or:
I recommend downloading Red Gate's .NET Reflector and use that for opening the umbraco dlls, and check out the code. You can even use it to search for the Node class and find it, once the umbraco.dll is opened.
Regards
Jesper Hauge
Wow that looks amazing, thanks.
is working on a reply...