Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi I am using umbraco 8, on some sub pages I want to call an item from the home page call it phoneNumber.
I know I can use the fall back
@Model.Value("phoneNumber", fallback:GallbackToAncestors)
But is there any way to just call it directly from the page it is on rather than the fallback.
Cheers
You can access that node directly from the umbraco helper, assuming that the homenode is at the root:
var homenode = Umbraco.ContentAtRoot().FirstOrDefault(); var telephone = homenode.Value("telephone");
or if, it's a child of the root node:
var rootNode = Umbraco.ContentAtRoot().FirstOrDefault(); var homeNode = rootNode.Children().Where(x => x.ContentType.Alias == "homeNodeContentAlias").FirstOrDefault(); var telephone = homeNode.Value("telephone");
Replace "homeNodeContentAlias" with the node content alias.
or relative, from current node:
var homeNode = Model.AncestorOrSelf(1); var telephone = homeNode.Value("telephone")
Excellent the top one worked a treat in this instance, the others will prove useful in future, thanks for your response.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Getting an Item from site route on any page
Hi I am using umbraco 8, on some sub pages I want to call an item from the home page call it phoneNumber.
I know I can use the fall back
But is there any way to just call it directly from the page it is on rather than the fallback.
Cheers
You can access that node directly from the umbraco helper, assuming that the homenode is at the root:
or if, it's a child of the root node:
Replace "homeNodeContentAlias" with the node content alias.
or relative, from current node:
Excellent the top one worked a treat in this instance, the others will prove useful in future, thanks for your response.
is working on a reply...