2

I have a text string property type that I use to display the "siteName" in the page title:

<title><umbraco:Item runat="server" field="siteName" recursive="true" /></title>

What code do I need in my .net usercontrol to add the "siteName"?

<asp:Label ID="siteName" runat="server" Text="siteName should go here!"></asp:Label>

Can anyone help?

I've added this to the Umbraco forum and was suggested the following, but not sure how to included it in my .ascx file:

dynamic node = new umbraco.MacroEngines.DynamicNode(umbraco.NodeFactory.Node.GetCurrent()); siteName.Text = node._siteName; 
JV10
  • 891
  • 3
  • 17
  • 40

2 Answers2

1

You can use this in a usercontrol

//var node = new Node(123); // Get node by Id, good if you have information on a certain page

var node = Node.GetCurrent(); // Get the current node
var nodeProperty = node.GetProperty("siteName").Value;
siteName.Text = nodeProperty;
Eric Herlitz
  • 25,354
  • 27
  • 113
  • 157
0

You want to have a public property in your usercontrol, and then when you expose the usercontrol to umbraco via a macro, that property will become a parameter of the macro as well.

When you reference the macro in your template, you can pas through the page property.

You might want to check out Umbraco tv:

http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/macro-parameters.aspx

And an old (but mostly accurate) pdf:

http://umbraco.com/media/42a0202c-b0ba-4f84-bcf1-64dfd5230322-usingcontrolswithumbraco.pdf

Jonathan
  • 4,916
  • 2
  • 20
  • 37