I have this simple partial which pulls some information about an application. I am starting to use visual studio instead of developing in the back office. How would I convert this to use model.content?
I have tried different variations of:
var selection = Model.Content.FirstChild("ApplicationDatabase").Children.Where("Visible").Take(4);
soTypedContentAtRoot will give you an IEnumerable of IPublishedContent of the root nodes in your Umbraco installation, so you can use this to find your site root node to query off
eg:
var siteRoot = Umbraco.TypedContentAtRoot().FirstOrDefault();
if (siteRoot != null){
var selection = siteRoot.FirstChild(f=>f.Name=="ApplicationDatabase").Children.Where(f => f.IsVisible()).Take(4);
}
or you can use AncestorOrSelf on Model.Content to interate up to the top level of your site (1 is the top level)
eg:
var siteRoot = Model.Content.AncestorOrSelf(1)
if (siteRoot != null){
var selection = siteRoot.FirstChild(f=>f.Name=="ApplicationDatabase").Children.Where(f => f.IsVisible()).Take(4);
}
Also take a look at the strongly typed razor cheat sheet, very handy when making the switch in syntax....
Switching from CurrentPage to Model.content
I have this simple partial which pulls some information about an application. I am starting to use visual studio instead of developing in the back office. How would I convert this to use model.content?
I have tried different variations of:
This is the code:
Hi Dustin
CurrentPage.Site() is a shortcut to get the current homepage when using the dynamic CurrentPage approach.
With Model.Content you have two options; use the UmbracoHelper methods:
https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/
soTypedContentAtRoot will give you an IEnumerable of IPublishedContent of the root nodes in your Umbraco installation, so you can use this to find your site root node to query off
eg:
or you can use AncestorOrSelf on Model.Content to interate up to the top level of your site (1 is the top level)
eg:
Also take a look at the strongly typed razor cheat sheet, very handy when making the switch in syntax....
https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets
Thank you very much for your help. That was just what I needed to get to the next level!
is working on a reply...