I am working on Sitecore Version 9.0.1
. I am looking to add a component to already existing pages. Since there are 100s of pages of this type, I was thinking to add component rendering to the standard values of the template. My question is, would this approach work even if the presentation details are overridden or would it require some custom script to achieve the result?
2 Answers
There are 2 Questions here:
1 - "looking to add a component to already existing pages. Since there are 100s of pages of this type"
Answer:
You are thinking in the correct direction. Add the rendering with data source in _Standard Values
of Template.
Note: If the data source expected for all the pages is different for the component you are trying to add, the approach will be different.
2 - Would this approach work even if the presentation details
are overridden
Answer:
Basically, all the Components you add to the "_Standard Values"
of a given template will be Stacked (no override)
Example: If you have a "NewsArticle" Component with placeholder "main", on the Page. Now you add the "NewsArticle" Component with the placeholder "main" into "_Standard Value"
on a given template, and it will be added to controls.
Yes, you can add the component to existing pages if you add the component to the Shared Layout of the Standard Values (as opposed to the Final Layout).
Ordering of renderings could be an issue, depending on your page structure.
At the end of the day, Layout is just XML:
Where:
- Renderings == Shared Layout
- Final Renderings == Final Layout
Final Layout applies XML transforms to the Shared Layout. For example:
SHARED
<r xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}" l="{1AC743C8-3703-4747-BE6D-15626041B41E}">
<r id="{3BAA694E-2AD1-4697-BA1C-DA376558E13D}" ph="structure" uid="{60DC7A51-E306-4981-B73D-1E2E5575CA70}" /
<r id="{C7789FEB-7EFF-4B3C-B319-59E5B6D5CF1B}" ph="structure" uid="{6426277D-DDED-4532-9CC9-E408CA96B51C}" />
<r id="{3BAA694E-2AD1-4697-BA1C-DA376558E13D}" ph="structure" uid="{F63A3522-57E0-4ED7-98E9-BF0DA8FA4C90}" />
<r id="{88553BE7-B7DB-420A-BC6E-5980AF8DD8C9}" ph="/structure/content-{6426277D-DDED-4532-9CC9-E408CA96B51C}-0" uid="{BF726EB2-9A95-44DC-A603-B40AF7920794}" />
<r id="{690D088F-46AF-4116-A4BE-6BA579B83141}" ph="/structure/content-{F63A3522-57E0-4ED7-98E9-BF0DA8FA4C90}-0" uid="{BAFBE8A1-042C-4447-BE2B-55A3A47E9614}" />
<r id="{1AC652A7-247E-4E99-91C4-D9985642B27C}" ph="footer" uid="{DB796DA4-78FB-4577-AF5F-E4D46B84C85D}" />
</d>
</r>
FINAL
<r xmlns:p="p" xmlns:s="s" p:p="1">
<d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}">
<r uid="{C3EFC9E6-C56D-4E32-A3B7-F00ED9444284}" p:before="*" s:ds="{F25132A8-F931-47C3-980D-C95FC4735EE9}" s:id="{AA478D5A-30CB-4E8C-BA5C-449F8D9A25E5}" s:par="EnableFadeIn=1" s:ph="/structure/content-{D5AD5D7F-FCB8-46EA-A47B-DEBA14D1122E}-0/highlight" />
<r uid="{B9B901E9-399B-4859-80A0-C9269274C8FE}" p:after="r[@uid='{C3EFC9E6-C56D-4E32-A3B7-F00ED9444284}']" s:ds="{242C72BF-7D8F-49DE-998D-BF5729B0E99B}" s:id="{AA478D5A-30CB-4E8C-BA5C-449F8D9A25E5}" s:ph="/structure/content-{D5AD5D7F-FCB8-46EA-A47B-DEBA14D1122E}-0/highlight" />
</d>
</r>
Notice the use of p:before
and p:after
.
Depending on how the existing components are ordered, it may work as is (as is often the case when adding a new component at the very top of bottom of a page), or you may need to do more extensive work, probably with Sitecore PowerShell Extensions (SPE).
My final recommendation would be to back up your items / database, go ahead and try adding your component to the Shared Layout, and if you have a specific issue, articulate that in your question.
-
Thank you so much Marcel. I will try that solution and will let you know! Feb 23 at 1:27