I am a newbie to sitecore and wanted to ask a question about layout inheritance. I am using web forms and do all my work using Sitecore Rocks. I have a base template that has three fields. I also have 2 other templates (Hardware and Product) that inherit from the base template. I have created a Hardware content item and under it is a Product content item.
I created my layout, sub-layout, and their respective definition item. In my layout I have a placeholder control so I can dynamically bind a component to it.
Now, I went ahead set the layout and sub-layout to the standard values of the base template. Now, by me doing this, will both the Hardware and Product items inherit the layout and sub-layout? I think the answer is yes because when I preview both items, they render per the layout and sub-layout I defined. Is this a standard practice? Also, if I define a different sub-layout for the Product item and set it to the standard values of the Product template, how come I get "...layout not found" error message when the layout is defined on its base template?
If someone could shed a light on this for me, I would appreciate it. I really want to get this concept down as I realize that it's the building block to Sitecore development.
The answer to your first question is YES, if you create a base template with some __StandardValues and you inherit the Product and Hardware templates from the base template, without defining their own standard values, any content items created from these templates will inherit the presentation details from the base template.
To answer your second question, you get a Layout not found, probably because you haven't defined a layout on the __StandardValues of the Product template, as you expect to be inherited from Base. But it does not work this way.
Let me explain:
In my screenshot below, you can see the three templates you mentioned. Note that:
BaseTemplate has __StandardValues
ProductTemplate inherits from Base but has no __StandardValues
Any content items created from this template will inherit form the StandardValues of the Base template, as no custom values exist
HardwareTemplate inherits from Base but has it's own _StandardValues
Any content items created from this template will not inherit from Base, it will use its own settings from _StandardValues
As soon as you change the Presentation Details of an item, your item will keep your changes.
A very detailed explanation on how Standard Values work can be found here: http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2013/01/all-about-standard-values-in-the-sitecore-aspnet-cms.aspx
Related
I've two layouts for the website, one for public (default) and other for private area, that I created.
When I create a new page (it uses the Public Layoyt by default) and if I want it to be with private layout I need to change in the Presentation > Details.
The problem comes after, I have default renderings in the Private Layout that aren't inserted on it.
So, my questions are:
Is there any possibility to ask the user when he creates a new page to ask for the layout?
Is possible for the Default Renderings in Private Layout to come together when changing the layout?
Am I doing right with having two layouts in the same instance of sitecore?
Thanks in advance!
Sounds to me like you should probably look into, creating 2 separate Page Templates.
Public Page
Private Page
These may inherit from common base templates.
Now, on each of these, configure Standard Values with the default presentation details you require - for the public and private layout respectively.
Alternatively (since I don't know exactly what you're trying to achieve) - Sitecore has something called Layout Presets. Described in section 3.6 here.
https://sdn.sitecore.net/upload/sitecore6/64/presentation_component_cookbook-a4.pdf
(very old document, but I do believe this still applies to current Sitecore releases)
One more alternative would be to create 2 branch templates
Public Page
Private Page
Works similar to how you would do it from 2 separate page templates, but removes the need for having templates that are there purely for presentation.
Then set your default presentation for each type of page on the branch template item. You can also set things like security options etc... just like you might with the standard values of a page template.
As an advantage over page templates, you can also create a child structure if needed - so if you had a /assets folder that you needed for each page type, a branch template is great for that.
In template, I have a parent template named:
BasePage
I added 2 sublayouts to BasePage template
sublayout1, sublayout2
I created a template (ChildPage template) that inherit from BasePage template. Now the ChildPage template also have 2 sublayouts via Standard Value. When I added sublayout3 to BasePage template WHY ChildPage template doesn't update ?
I have to use Reset Layout to Standard Value it was updated.
Just please do correct me if my understanding to your question is incorrect.
So..
You have a base template and this base template has 2 controls (sublayout).
You also have page template (child page) that has 2 controls (sublayout), as well. The page template inherits to the base template which has (2 controls)
So you have like this:
Base template (2 controls)
Page template (2 controls)
Then you added another control to the Base template, so the Base Template has 3 controls now.
Base Template (3 controls)
And your expectation is by adding a rendering control in the Base template, the changes will get cascaded in its implementer in your case, the page template?
If so, then, as from what I understand about inheritance, if the Standard Value of the page template (implementer) was not yet touched, meaning you didn't edit the presentation details. The changes from the base template rendering controls will be automatically cascaded to the page template. Otherwise, as from what you have experienced. It didn't reflected and therefore you were forced to reset the layout. After resetting the layout, and add another rendering control to the base template it will cascade automatically again.
I simulated your issue in a fresh installed v.8.1-U2 and I got the same experience, though, this is different from your current version. I hope you were also able to simulate it on your end.
If the problem still persist, after trying the above steps I did, then you probably might want to contact Sitecore support. But before doing that, try to recreate the issue on the fresh installed Sitecore instance. Thanks.
I have template (A) and template (B).
B template has base template (A). But, if I update layout presentation in template (A)'s standard values, it doesn't effect on template (B)'s standard values.
Why???
This is an issue to do with the way the layout is stored in the standard values. As soon as you change the presentation details of template(B) Sitecore will copy the __renderings field value from template(A). Standard values unfortunately store the full definition of the layout, not just the change deltas like regular items and so the link is broken for the layout details between the 2 templates.
You can write a Item Saving event handler to "copy up" the calculate the differences and apply those. You can find more info and code in this blog post by Przemek Taront:
Complex layouts in Sitecore using standard values hierarchy
You need to click Reset under Layout ribbon on Template B's standard values.
Is it possible to add a sublayout(usercontrol) across a few templates without manually adding one by one to each of the templates?
Currently, we are adding all the common sublayouts to each of the templates _standard values and rendering them. Looking for a better implementation.
This is a great case for using inheritance with your Data Templates. By inheriting from a "base" template, the other templates can be controlled from a single location - the standard values of the base template.
Alternatively, you can use the "Copy To" feature located in the Presentation > Details dialog to easily copy presentation from one item to another.
The third option is to bake your Sublayout into the Layout by adding it directly to the .aspx or .cshtml file. However, in this scenario, the Sublayout would appear on all items that used that layout, unless it contained logic to conditionally render itself.
To avoid adding the sublayout on each and every template,
Create a Template add all required fields on the same.
in its standard values assign the sublayout.
Inherit this template in all required templates.
This will help in 2 cases.
you dont need to create common fields in all the templates
you dont need to assign the common sublayout in all the templates.
I have a page which displays 2 types of information: general (user name/full name of the current user for ex) and specific (a list of friends if the page is "Friends" ).
When going to another url, the general information remains unchanged, while the specifics change ( a list of locations for the "Locations" page).
So far I implemented this using a views hierarchy: the base view is responsible for the general information, while the child view is responsible for the specifics.
In templates I use "extends": base template -> general information, specific template that extends the base template -> specific information.
All works well.
Now I decided to use django-postman, and I want to embed the postman template in the base template.
My question is: what is the best way to do this?
So far the only solution I could find was to use "extends" and add code that adds what I need into context to the django-postman views. I do not like this solution at all.
Is there a more elegant way?