I have some properties like CompanyName that is placed on the frontpage documenttype. It is edited only on the frontpage but the values are used on all pages.
In _Layout.cshtml I have: var companyName = Umbraco.Field("companyName", recursive: true); wich works fine in U7.
I have "@inherits Umbraco.Web.Mvc.UmbracoViewPage" at the top of _Layout.cshtml.
I have in my new U8 site tried Model.Root() and Model.Value but i get an error saying: "IPublishedContent does not contain a definition for Root" and the same for Value.
I use CurrentPage.Level and CurrentPage.Url and converted that to Model.Level and Model.Url wich works fine so Model is awailable just not Model.Root() and Model.Value.
So Model.Root() is equivalent to Model.Content.AncestorOrSelf(1) right.
And if I need documenttypealias "CompanyName" from FrontPage I do it like this?
var frontpage = Model.Root();
var companyname = frontpage<string>("CompanyName");
if it's not erroring - but just not pulling the ancestor value from your root node, then obvious things are if the alias is different, or the node isn't under the root in the tree - less obvious is if one of the ancestor nodes between your page and the root, has a value, a space or some json markup that is not visible, but prevents the Fallback from going all the way up the tree.
Converting from U7 V7.15.4 to U8 V8.10.0
Converting from U7 V7.15.4 to U8 V8.10.0
I have some properties like CompanyName that is placed on the frontpage documenttype. It is edited only on the frontpage but the values are used on all pages.
In _Layout.cshtml I have: var companyName = Umbraco.Field("companyName", recursive: true); wich works fine in U7. I have "@inherits Umbraco.Web.Mvc.UmbracoViewPage" at the top of _Layout.cshtml.
I have in my new U8 site tried Model.Root() and Model.Value but i get an error saying: "IPublishedContent does not contain a definition for Root" and the same for Value. I use CurrentPage.Level and CurrentPage.Url and converted that to Model.Level and Model.Url wich works fine so Model is awailable just not Model.Root() and Model.Value.
What to do please?
Hi Rasmus
Model.Root() and Model.Value
https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Web/PublishedContentExtensions.cs
which is Umbraco.Web
So if you can put a @using Umbraco.Web statement at the top of your view that might give you the access you need to call .Root() and .Value()
You would use the 'Fallback To' methods to use FallBack.ToAncestors to replace the recursive call you had in Umbraco.Field:
https://our.umbraco.com/documentation/getting-started/design/Rendering-Content/#using-fall-back-methods
regards
Marc
Hi Marc
Thanks a lot, that did the trick :)
So Model.Root() is equivalent to Model.Content.AncestorOrSelf(1) right. And if I need documenttypealias "CompanyName" from FrontPage I do it like this?
As for the other it seems to work with
But not with
Can't it be strongly typed?
Thanks
Ahh this seems to work
Strange this does not...
Is it because it might be null if no ancestors has data?
Hi Rasmus
The fallback option that doesn't work
does it error, or just not pull back the value from higher up the tree?
If the compiler throws an error, then try wrapping the Model.Value part inside @() brackets like so:
if it's not erroring - but just not pulling the ancestor value from your root node, then obvious things are if the alias is different, or the node isn't under the root in the tree - less obvious is if one of the ancestor nodes between your page and the root, has a value, a space or some json markup that is not visible, but prevents the Fallback from going all the way up the tree.
regards
marc
Hi Marc
This works:
This does not:
because of the
<string>
and it is not supposed from the documentation. So everything is fine. https://our.umbraco.com/Documentation/Reference/Querying/IPublishedContent/Properties/#fallbacksI just wonder why it can not be strongly typed when using Fallback.ToAncestors when it can when not using Fallback or Fallback.ToDefaultValue.
is working on a reply...