read properties from a settingspage in my partialHTML-View
Hey guys,
I've created a "general Settings" page below the root Element. In my partialHTML-Views I want to read those properties, but I have problems with getting those values.
First, I tried to select the properties-page with this segment:
var rootNodes = Umbraco.TypedContentAtRoot();
var settings = rootNodes.First(x => x.DocumentTypeAlias == "GeneralSettings");
I only have access to the GetPropertyValues()-Method for the settings-page, if i put this code outside of my RenderPartial and transfer it as model-object to a partialHTML. I tried to put this variable also in a ViewBag. But it is still not working.
I would like to use this settings-variable globally, but I have no idea how to achieve this. Because the current project environment doesn't allow me to create Controller-Classes. I may only write code in the frontend-templates. So I am limited in my actions.
I do the same when creating websites through Umbraco.
My technique is the following:
var homePage = Model.Site();
var Settings = homePage.Descendants("generalSettings").FirstOrDefault();
if(Settings == null)
{
//Return null or fix as settings returning full with make the website break
return;
}
I work using IPublishedContent:
@inherits UmbracoViewPage<IPublishedContent>
at the top of my partial so this may differ slightly for you depending on what you are using.
Thanks,
Lewis
(side note, when trying to get content from the settings tab you can do this easily by the following:)
Is it possible to you to move settings properties to root node?
It will be the most efficient way in a sense of performance of page loading because code like getting settings node that is the same level as root but not home page - it's not needed traversing over the tree. We can avoid this traversing if we move properties to root node.
Lewis, this code isn't fast:
var homePage = Model.Site();
var Settings = homePage.Descendants("generalSettings").FirstOrDefault();
if(Settings == null)
{
//Return null or fix as settings returning full with make the website break
return;
}
Add this code to each page where you need settings - potential performance problem.
my generalSettings - Page is on the root node. I'll give it a try with searching for DocumentType instead, maybe the first()-Method returns the wrong object.
I inherit from Umbraco.Web.Mvc.UmbracoTemplatePage, maybe this is the problem?
Yeah, I used the correct Alias. But if I use the same code in a partialHTML the object is not a IPublishedContent. It was rather a XML-Object, I don't remember at the moment.
So I thought it has something to do with the namespace.
read properties from a settingspage in my partialHTML-View
Hey guys,
I've created a "general Settings" page below the root Element. In my partialHTML-Views I want to read those properties, but I have problems with getting those values.
First, I tried to select the properties-page with this segment:
I only have access to the GetPropertyValues()-Method for the settings-page, if i put this code outside of my RenderPartial and transfer it as model-object to a partialHTML. I tried to put this variable also in a ViewBag. But it is still not working.
I would like to use this settings-variable globally, but I have no idea how to achieve this. Because the current project environment doesn't allow me to create Controller-Classes. I may only write code in the frontend-templates. So I am limited in my actions.
Do you have any ideas?
Thanks in advance.
Hi Nadine,
I do the same when creating websites through Umbraco.
My technique is the following:
I work using IPublishedContent:
at the top of my partial so this may differ slightly for you depending on what you are using.
Thanks, Lewis
(side note, when trying to get content from the settings tab you can do this easily by the following:)
Hi Nadine,
Is it possible to you to move settings properties to root node?
It will be the most efficient way in a sense of performance of page loading because code like getting settings node that is the same level as root but not home page - it's not needed traversing over the tree. We can avoid this traversing if we move properties to root node.
Lewis, this code isn't fast:
Add this code to each page where you need settings - potential performance problem.
Thanks,
Alex
my generalSettings - Page is on the root node. I'll give it a try with searching for DocumentType instead, maybe the first()-Method returns the wrong object.
I inherit from Umbraco.Web.Mvc.UmbracoTemplatePage, maybe this is the problem?
Umbraco.Web.Mvc.UmbracoTemplatePage shouldn't be a problem.
"GeneralSettings" is it a right doctype alias?
Yeah, I used the correct Alias. But if I use the same code in a partialHTML the object is not a IPublishedContent. It was rather a XML-Object, I don't remember at the moment.
So I thought it has something to do with the namespace.
Hello, when I have a node that is settings:
is working on a reply...