Spanky
Spanky

Reputation: 709

How do I select an element based off the value of the parent in an Umbraco.config file?

Please bear with me because I am very new to Umbraco.

I have a test Umbraco config file that looks like the following:

<Product nodeName="For-test">
    <customId>222/</customId>
</Product>

<Product nodeName="For-none">
    <customId>333/</customId>
</Product>

In my test.master page, I would only like to match the child element who's parent has the value of "For-test". This should give me the value of "222". I am using the following code to display the element values but I get the following error "Error loading MacroEngine script (file: )" I believe that my syntax is wrong.

<umbraco:Macro runat="server" language="cshtml">
    @Model.nodeName="For-test".customId;
</umbraco:Macro>

Upvotes: 0

Views: 105

Answers (2)

Silv
Silv

Reputation: 773

For a detailed error go to App_Data/Logs/ and open the newest .txt file.

Upvotes: 0

Jannik Anker
Jannik Anker

Reputation: 3425

Which Umbraco version are you using? Version 7 is best when using MVC, so you wouldn't typically have a master page at all.

Also, you shouldn't have to be fiddling with umbraco.config at all.

I would suggest you start by installing the starter kit (maybe in a fresh install?), then you can check out how "it" does things. Also, have a good look in the documentation (https://our.umbraco.org/documentation/) and maybe even check out some of the video tutorials (something like these http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/templating/).

As for your specific question:

  1. No need to use the <umbraco:Macro /> tag - but since you are in a Web Forms type website (and not MVC), you can't use @ to indicate code sections. You'll have to try with <%= %>.
  2. The Umbraco Model is tied to whatever page you are viewing. You can query for content by Id or "nodeTypeAlias" (which in your case would be "Product", and you'd get all Products at once), but not easily by name since it isn't unique.

But I think you can get a much better grasp of how things are done in Umbraco by looking at the links provided above.

Upvotes: 4

Related Questions