I'm currently building some Razor Views and have found there's many ways to skin this cat.
My preference is to use uQuery as it's consistent, but as a matter of principle, I'm building a new project using the new API's. Whilst looking at the documentation for the MNTP I've become a little confused, as (for me) it seems not to work.
It seems that in the given examples, the API no longer exists. So I have updated the code to the following...
@* look at the currentPage, does it contain any values for 'contentRelations'? *@
@if (@CurrentPage.HasValue("contentRelations") && (@CurrentPage.contentRelations.ToString()) != "")
{
foreach (var x in CurrentPage.contentRelations)
{
var n = @Umbraco.Content(@x.InnerText);
// do something
}
}
Is this the right way to go about this?
Could the check be better? (I know it's a MNTP, so can I use that to my advantage, rather than !="")
If this is right, should I update the wiki?
Should I write code add these items to the Model, rather than littering the view.
I've had several frustrations over time dealing with MNTP's values as XML and now exclusively store them as CSV. Then I just get the value as a string and .Split(',') works great. I don't have to worry about the value's typing or structure changing over time, nor the unintuitive dealing with getting anything out of the XML which I used to do similar to how was shown above. Much easier now for me at least. Good luck to you!
v6 API Documentation for MNTP
Hello,
I'm currently building some Razor Views and have found there's many ways to skin this cat.
My preference is to use uQuery as it's consistent, but as a matter of principle, I'm building a new project using the new API's. Whilst looking at the documentation for the MNTP I've become a little confused, as (for me) it seems not to work.
Umbraco Documentation - get Values from uComponents
It seems that in the given examples, the API no longer exists. So I have updated the code to the following...
Thanks! Laurence
Hey Laurence,
Have you considered a Property Editor Value Converter for MNTP? There is one included in this package
Then you only need the following and x would be the IPublishedContent object
Cheers,
Jeavon
If you use the strongly typed version you can also use extension methods. This is how I'm using MNTP:
Extension method:
Which you can use like this:
Jeroen
I've had several frustrations over time dealing with MNTP's values as XML and now exclusively store them as CSV. Then I just get the value as a string and
.Split(',')
works great. I don't have to worry about the value's typing or structure changing over time, nor the unintuitive dealing with getting anything out of the XML which I used to do similar to how was shown above. Much easier now for me at least. Good luck to you!is working on a reply...