I have an ultimate picker set up called centreAuthors, but when I add @Model.centreAuthors to the template I get the ids for each of the nodes picked. I've tried a few different . syntaxes like getproperty etc but can't seem to find the correct syntax.
The picker will return node ids. What you need to do is create an instance of a node or IPublishedContent (depends on version) using NodeFactory or ContentService and pass in the id you get back as the parameter. This will give you an object with properties on :).
@{
var dynamicUltimatePicker = CurrentPage.centreAuthors.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
var dynamicUltimateCollection = Umbraco.Content(dynamicUltimatePicker);
foreach (var item in dynamicUltimateCollection)
{
<p>@item.Name</p>
}
}
@Charlie, you should never use the ContentService on a front end website for querying data, it is a management API. You should be using @Umbraco.Content or @Umbraco.TypedContent
@Tom, please note that this snippet should be used in a MVC view, partial view or a partial view macro.
If you are using a legacy Razor Macro (Scripting File) then the solution you need is the DynamicNode example on the documentation page. However, if you can you should change to one of the supported methods.
centreAuthors is the name of the property Authors is the name of the datatype which is an ultimate picker (not sure if you need that information?)
I understand the method of reading in the CSVs from the picker and splitting them up using a for loop, but I very rarely code using razor so I'm not sure which bits to keep and which bits to ditch and where to put everything. All I seem to get no matter what I do is a big error splatted into the centre of the page...
It looks very close to me! I only have my mobile phone right now so I can't test I to find the issue is, but I will later. Does the error say anything useful?
In /config/umbracoSettings.config there is a setting to control how macro engine errors are managed, you could change this to "throw" to see if you get something more meaningful
It's because the method you are using for rendering here "Razor Macro" is legacy. It is recommended that you use a Partial View Macro if you are using WebForms templates (which it looks like you are) or direct MVC templates/partials. However there is currently a lot of confusion and many beginners start using the legacy method and also there is a large body of samples. Hopefully in v7.2 this will be reduced as the legacy "Razor Macros" will be hidden and in v7 MVC is the default rendering engine.
Simple answer?
Pretty straight forward question really.
I have an ultimate picker set up called centreAuthors, but when I add @Model.centreAuthors to the template I get the ids for each of the nodes picked. I've tried a few different . syntaxes like getproperty etc but can't seem to find the correct syntax.
Any help would be much appreciated!
Thanks,
Tom
Hopefully the simple answer you seek is here?
I've looked through that page before but couldn't work out what it was telling me to do..
Which code should I be basing my solution on? The Typed example?
Thanks,
Tom
The picker will return node ids. What you need to do is create an instance of a node or IPublishedContent (depends on version) using NodeFactory or ContentService and pass in the id you get back as the parameter. This will give you an object with properties on :).
You will need to split the ids on the ',' so
IEnumurable<int> authors = Model.createAuthors.Split(',')
Charlie :)
@Tom, try this
@Charlie, you should never use the ContentService on a front end website for querying data, it is a management API. You should be using @Umbraco.Content or @Umbraco.TypedContent
Jeavon
@Tom, please note that this snippet should be used in a MVC view, partial view or a partial view macro.
If you are using a legacy Razor Macro (Scripting File) then the solution you need is the DynamicNode example on the documentation page. However, if you can you should change to one of the supported methods.
This is at the top of the page:
I guess that means I need to use the dynamicNode example?
My brain's fried and I think I'm substituting the wrong aliases into the code! :(
I have a razor macro and what I'm looking to replace is the following:
centreAuthors is the name of the property
Authors is the name of the datatype which is an ultimate picker (not sure if you need that information?)
I understand the method of reading in the CSVs from the picker and splitting them up using a for loop, but I very rarely code using razor so I'm not sure which bits to keep and which bits to ditch and where to put everything. All I seem to get no matter what I do is a big error splatted into the centre of the page...
Ok, fear not Tom, I will post a solution for you. What version of Umbraco are you running?
Thanks Jeavon. Using v6.2.1
Just out of interest, am I close with this?
It looks very close to me! I only have my mobile phone right now so I can't test I to find the issue is, but I will later. Does the error say anything useful?
Annoyingly no..
Error loading MacroEngine script (file: )
In /config/umbracoSettings.config there is a setting to control how macro engine errors are managed, you could change this to "throw" to see if you get something more meaningful
Nope... Just the same..
Ah ok, I've just checked it out and it was only a missing code block.
Try this:
Perfect. :)
Thanks a lot for your help.
You're very welcome! Can I ask, are you building a new site in Umbraco v6.2.1 or is it a upgrade of a old site?
Building a new site - why?
It's because the method you are using for rendering here "Razor Macro" is legacy. It is recommended that you use a Partial View Macro if you are using WebForms templates (which it looks like you are) or direct MVC templates/partials. However there is currently a lot of confusion and many beginners start using the legacy method and also there is a large body of samples. Hopefully in v7.2 this will be reduced as the legacy "Razor Macros" will be hidden and in v7 MVC is the default rendering engine.
Ah. Thanks for the tipoff.
I'll look into the newer stuff when I get a chance. I agree - it does get confusing.
is working on a reply...