I have been struggling with a Razor script for many hours now, and finaly admits that i need help :)
The script is a "Info-box" that will be shown in the right side of a text-page. The user have the option to choose to show the box or not (true will show a random box) or choose from the content-picker a specifix info-box on a specific textpage. I have figured out how to show the random info-boks if you check it to true, but the specific info-box is really troubling me.
A brief explenation of the content in the code:
"visBoks" = the truefalse checkbox to show a random info-box. (Generic prop on the Textpage doctype)
"Model.NodeByID(1362)" = The ID refers to the container(in the content) of the infoboxes.
"vlgInfoboks" = The Content-picker that i use to choose a specific info-boks to show (Generic prop on the Textpage doctype)
The page.visteDuOverskrift (etc..) is generic properties that creates the content on the specific info-box
When i run the script it works perfect when i visBoks checkbox to true. But when i choose a specific info-box from the content-picker it dosnt show anything.
(Got a xslt-error when trying to edit the above post)
To grab a specific node you the Library.NodeById(nodeId) helper. That said, something like this would probably work. Note I also moved your infobox div into a helper to avoid duplication :)
@{ if (Model.visBoks == true && !Model.HasValue("vlgInfoboks")) { var randomPage = Model.NodeById(1362).Children.Random(1); @ShowInfoBox(randomPage); } else if (Model.visBoks == true && Model.HasValue("vlgInfoboks")) { var page = Library.NodeById(Model.vlgInfoboks); @ShowInfoBox(page); } }
Thank you very much! It was a great help and i finaly got it working.
Your code didn't work just by cpoy/paste. There where som problems with the definition og "page". So i had ditch the @helper (although a very cool feature) and bring back the mess. I know it's not pretty, but this got the whole thing working:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{ if (Model.visBoks == true) {
foreach (var page in Model.NodeById(1362).Children.Random(1)) { <div class="block_box_i"> <h2>Viste du at..</h2> <p>@page.visteDuOverskrift</p> <a class="more_link_s" href="@page.linkTilSideVisteDu">@page.visteDuLinktekst</a> </div> } } else if (Model.HasValue("vlgInfoboks")) { var page = Library.NodeById(Model.vlgInfoboks); <div class="block_box_i">
Showing specific page from contentpicker
Hi guys
I have been struggling with a Razor script for many hours now, and finaly admits that i need help :)
The script is a "Info-box" that will be shown in the right side of a text-page. The user have the option to choose to show the box or not (true will show a random box) or choose from the content-picker a specifix info-box on a specific textpage. I have figured out how to show the random info-boks if you check it to true, but the specific info-box is really troubling me.
A brief explenation of the content in the code:
"visBoks" = the truefalse checkbox to show a random info-box. (Generic prop on the Textpage doctype)
"Model.NodeByID(1362)" = The ID refers to the container(in the content) of the infoboxes.
"vlgInfoboks" = The Content-picker that i use to choose a specific info-boks to show (Generic prop on the Textpage doctype)
The page.visteDuOverskrift (etc..) is generic properties that creates the content on the specific info-box
This is what i got so far:
I'm all new to coding in general, so I really appreciated all the help i can get
When i run the script it works perfect when i visBoks checkbox to true. But when i choose a specific info-box from the content-picker it dosnt show anything.
(Got a xslt-error when trying to edit the above post)
Here is how the content is structured:
Hi,
To grab a specific node you the Library.NodeById(nodeId) helper. That said, something like this would probably work. Note I also moved your infobox div into a helper to avoid duplication :)
-Tom
Hi Tom
Thank you very much! It was a great help and i finaly got it working.
Your code didn't work just by cpoy/paste. There where som problems with the definition og "page". So i had ditch the @helper (although a very cool feature) and bring back the mess. I know it's not pretty, but this got the whole thing working:
Again, thanks for all you help :)
is working on a reply...