I have a controller that pulls data from the data node.
How do I specify that on .dk it should pull from
dk
widget??
right now im using
var root = contentService.GetById(Umbraco.TypedContentAtRoot().First().Id);
var widgetPage = root.Descendants().Where(x => x.ContentType.Alias.Equals("widgetsPage")).FirstOrDefault();
but that will of course only get data from the first root.
I need some how to find the current root i'm on..
Its very important that you never use the Content Service where the end user will access it. It has a terrible performance (always sql, not caching) and you don't need it.
You would instead do:
var rootNode = UmbracoContext.PublishedContentRequest.PublishedContent.Site();
var widgetNode = rootNode.Children.FirstOrDefault(x => x.DocumentTypeAlias == "widgetsPage");
.Site() will always fetch the root node of the page dependent on the node you are on.
Multi language page - controller
I have a site with a
I have a controller that pulls data from the data node. How do I specify that on .dk it should pull from
right now im using
but that will of course only get data from the first root. I need some how to find the current root i'm on..
Any suggestions? :)
Thanks!
Hi Thomas.
Its very important that you never use the Content Service where the end user will access it. It has a terrible performance (always sql, not caching) and you don't need it.
You would instead do:
.Site() will always fetch the root node of the page dependent on the node you are on.
Recommend you check the common pitfalls for Umbraco here: https://our.umbraco.com/documentation/reference/Common-Pitfalls/
Hey :)
This is in my controller
Yes but I guess the controller is accessed from the frontend and it will return data to the site.
In that case never use the content service unless you know exactly what you are doing.
You have much better access to the nodes with Umbraco.TypedContent or UmbracoContext.PublishedContentRequest.PublishedContent.
For example in this line you already have access to the IPublishedContent version of the node with this:
There is no reason to fetch it again with the content service.
Are okay thanks :)!
Do you know how to get the root of the specific culture page?
Depends on where you are trying to access it.
Do you for example only have the culture name?
Or are you on a sub page and need to get the correct root page ?
This code will fetch the correct root page.
Will fetch DK
from www.test.dk I would like to fetch data from
and from www.test.com I would like to fetch data from
from the controller :)
with that code you sent i'm getting 'Object reference not set to an instance of an object.'
How are you calling the action in the controller ?
Right now from postman.
But will eventually use ajax call to the controller
You dont have access to the UmbracoContext when using Postman.
Could send the current page id you are on to the action.
If you dont have access to Umbraco.TypedContent Then you can use
https://our.umbraco.com/documentation/Reference/Querying/UmbracoHelper/
is working on a reply...