Interesting scenario that I haven't come across before. Say for example I have a "Base" template that sets some top content variable like so:
var topContent = Model.Content.Children().FirstOrDefault(x => x.DocumentTypeAlias == "TopContent");
The base template renders some page areas with reference to this topContent var.
Then I have a "Child" template whose layout is set to "Base", this child template also has the same line of code to set the top content and render some different content.
So, during the page render process does the system cache the base template topContent result and just re-use it from Child, or does it result in two trips to the database (or content cache)? Assuming for the moment that it results in two trips, what is the best way to make variables from a base template available to templates that inherit from it? The simplest way I can think of is to set and use ViewData from the base template but I don't like that as a solution, it's not very elegant.
So, thought I'd throw this one out to the community for comment. Any thoughts?
You should use a specific model that you generate only once in your controller with the advantage that you run the queries only once, if you need to access multiple time properties in your view there are parsed only when you create your model, and not each time you access a property of your IPublishedContent.
Passing vars from base template to child template
Interesting scenario that I haven't come across before. Say for example I have a "Base" template that sets some top content variable like so:
var topContent = Model.Content.Children().FirstOrDefault(x => x.DocumentTypeAlias == "TopContent");
The base template renders some page areas with reference to this topContent var.
Then I have a "Child" template whose layout is set to "Base", this child template also has the same line of code to set the top content and render some different content.
So, during the page render process does the system cache the base template topContent result and just re-use it from Child, or does it result in two trips to the database (or content cache)? Assuming for the moment that it results in two trips, what is the best way to make variables from a base template available to templates that inherit from it? The simplest way I can think of is to set and use ViewData from the base template but I don't like that as a solution, it's not very elegant.
So, thought I'd throw this one out to the community for comment. Any thoughts?
You should use a specific model that you generate only once in your controller with the advantage that you run the queries only once, if you need to access multiple time properties in your view there are parsed only when you create your model, and not each time you access a property of your IPublishedContent.
is working on a reply...