Sitecore Base Template - sitecore

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.

Related

Where to set sitecore layout and sub-layout

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

Why we use Reset Layout to Standard Value?

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.

Need clarity on Sitecore template values, standard values, and branch templates

Relatively new Sitecore dev here and I'm trying to get some clarity on simple topics, so I have a few questions.
When creating a data template: what is the difference between just filling in the values on the template, and adding standard values? Don't both become default values whenever you create an instance of that template? If I want to make sure each item of a template has a certain value, which should I use and why? When is it appropriate to just fill out the value on the template, as opposed to adding standard values?
Branch templates: I need to create a group of items whenever a single item is created, and it sounds like branch templates are perfect for this. However, I recently read that instantiated items from a branch template stop inheriting the moment they're created.
For example, I have a branch template called Store, and create an item based off of this called Walmart. I then add features to the Store by adding new items, but Walmart doesn't get those changes? If this is problematic to my situation. I really need to keep all instantiated items in line with the branch template, and give them the new features. If my understanding is correct, how can I get around this?
Thanks
Templates. For mature .NET developer it would make sense to think about templates as about C# classes - they define the data structure for the items that would be created on that particular template. Like classes in C# they may be inherited, but unlike in C# multiple inheritance is supported with them.
Official documentation on templates is quite descriptive and handy: https://sdn.sitecore.net/upload/sitecore7/70/data_definition_api_cookbook_sc70_a4.pdf
Standard Values is a kind of blueprint prototype item for your template. You create some default values that will be auto-filled as soon as you create an item of that particular template. Standard Values item is a child item of a template definition item. You may also use tokens - dynamic values like $name, $parentname, $date, $time, $now, $id and others (you may also create your own tokens). Please read more about standard values: http://goo.gl/uUZJZf
Branch templates allow you to re-produce a sub-tree on instantiation, not just one item, but also some children (and children of those children) as you specify in branch template itself. As on screenshot below, whatever is selected within red frame will be created as a result of branch template instantiation:
Also, Sitecore items can't inherit from values set in a branch template. They will always default to the values in the original template's standard values. This is a limitation of branches (as described in this SO question: http://goo.gl/PSElYy)
As far as I understood your case, you should have a branch template called Store (somewhere underneath /sitecore/templates/Branches) and within that item reproduce exact structure that will be created on when template is used to replicate into a new branch in your content. Again, you may use tokes all around branch template (at any level) - they would be replaced with actual values. Likewise, when you use your Store branch template to create Walmart, you may auto set its display name to Walmart by using $name token.

How to make a Field Section appear first?

I have a page template that inherits multiple data templates.
Take for example: Event Page
which inherits: Basic Page, HasDateRange, and HasLocation
Now, I want the Date Range field group of the HasDateRange template to appear first when editing Event Pages. That's a simple example, but in general, how can I influence the field group order on templates when using multiple inheritance? Let's say I don't need DateRange at the top of one template and at the bottom of another... I generally have more important fields that need to appear at the top of every template they are included on.
Not sure it matters, but I am using Sitecore version 7.1
Template Section items have a sortorder field which accepts an integer. That number governs the order in which sections will appear.
Here's an article from the Sitecore site:
Sorting sections in templates
Also, see the following Stack Overflow question:
Sortorder of Inherited Templates

Sitecore presentation details don't update on template change

I'm working on a Sitecore (6.4.0.101124) site that has two templates used for the home page. These have a very similar structure - the big difference between them is that they each have one different sublayout in the Controls section of the Presentation Details of the Standard Values. My understanding is that when the template is changed on an item the standard values of the template should be applied to that item. However, when the content editors change the template the presentation details remain the same until I go in and change them.
So this means that either I misunderstand how this is supposed to work, or something wonky is happening. This is a very similar problem to what's discussed in this thread, but the answers given don't seem to apply since this item was not created using a branch template.
Has anyone had a similar experience with this (and solved it)? Am I way off base in how this is supposed to work?
You write:
My understanding is that when the template is changed on an item the standard values of the template should be applied to that item.
This is only true if a field has not been edited. Once a field for an item has been edited, the edited value takes precedence over the default. Changing the template to one that has different Standard Values will only have an impact if the field has not been touched, or if the user resets the field to the default value using the Fields Reset button. (Note that manually clearing the field will not do the trick. Sitecore will store an empty string, which will override the Standard Value. By using the Reset button, you set the field to a Database Null, which causes the Standard Value to be used.)
You can tell if a field has been edited by checking for the text "standard value" next to the field in the Content Editor:
Sitecore 6.4.0 and Layout Deltas
Things are more complex with the Renderings field on Sitecore 6.4.0 and above, because Sitecore introduced a feature called "Layout Deltas" with this release. Before Layout Deltas, if you edited the presentation details of an item, Sitecore would copy the layout information from the "Renderings" field of Standard Values into the item's Renderings field, which had the consequence that any subsequent change to Standard Values Renderings would have no effect on the display of this item.
This functionality made it difficult to manage changes to presentation, since a minor change to a detail of presentation on an individual item, such as adding conditional rendering logic, would break the inheritance from Standard Values. If if was necessary to change the presentation of a class of items, it was necessary to first change Standard Values, and then to make the same change to every item that modified presentation.
With Sitecore 6.4's Layout Deltas, if you modify the presentation of an item, just the change is stored in the item's Renderings field, rather than a complete copy of the Standard Values rendering. This change, or delta, information is applied on top of the Standard Values Renderings information, so that modifications to Standard Values layouts are applied to all inheriting items, not just ones with unmodified presentation.
It sounds like your content editors have made a modification to the presentation of the item. When the template is switched, this change is being applied on top of the new template. You can confirm this by checking for the [Standard Values] text next to the Renderings field of the item in question.
The template has values, but what carries the values to the items that are created using that template is in the standard values item. Now, that being said, each field on an item that is created from that template has a flag that says whether or not its using template standard values. If the presentation details are NOT flagged as using standard values still, then its not going to cascade down the updates to the items.
Now.. to be sure that you understand the difference between a branch and a template.. a branch is sort of a "model" of how you can create an item. It is NOT going to cascade changes down when you make changes to the branch item at all. Items will inherit values from their TEMPLATE standard values. The branch values inherit only upon item creation.
EDIT: By the way, I should add that if you turn on the gutter on the left to show presentation overridden, you can see if the presentation values are standard values or not. If you see the icon, then you know the item is not currently using standard values.
I got to this question because I had a field across hundreds of pages which I needed to change. It was not shared to begin with. I tried setting the field to Shared & Unversioned within the template but that did not cause it to change everywhere when I made changes.
I then proceeded to set a Standard Value in the template to what I wanted the field to be, and then selected Versions -> Fields -> Reset after highlighting the Standard Value. The first time I did this, it reset the field to blank. Then I did it again and the field changed on every page which used that particular field. Hope this helps. It seems if you already have a field which wasn't shared to begin with, you need to do a standard value reset to it.