Blog Banner

Rule Placeholders

Decouple Placeholder Management with Allowed Rendering Rules

The best Sitecore solutions I’ve seen use component driven design. This eases future maintenance and gives a plug-n-play feel where you can add or remove modular, well-defined features. Sitecore’s well-documented Helix principles and the community’s adoption has greatly encouraged this design practice.

However, every once in a while I run into a conflict on placeholder setting items. Let’s say one module introduces a placeholder, then another module, or even the site implementation, wants to add an allowed rendering for that placeholder. In order to make this configuration, you are coupling the modules or rigging it just for this implementation. I ran into this lately when using SXA, and wanting to add a custom rendering to the SXA mvc form placeholder. If I edit the SXA placeholder definition item, I risk having it undone with the next SXA upgrade and I doubt anyone will notice except for the authors that are left scratching their heads!

Sitecore’s insert option rules have expertly resolved these sorts of issues for me in the past in regards to insert options between modules, and they were the inspiration behind extending placeholder management in a similar way. Below is a link to the latest Sitecore Package and source code. Mimicking insert option rules, I added a place under /sitecore/system/settings/rules for Placeholders and provided matching conditions and actions to add, and even remove, allowed components for placeholders. This works to show or hide components from the add component dialog for any placeholder. The rule is evaluated after all the normal configuration in the getPlaceholderRenderings pipeline.

I’ve enjoyed the separation of concerns this provides. I hope you can find it useful too!

GitHub Release (https://github.com/digitalParkour/Community.Foundation.PlaceholderRules/releases)

Screenshots (https://github.com/digitalParkour/Community.Foundation.PlaceholderRules/wiki/Usage)

Contact Us Today!

James is an NIU grad with a major in computer science, theoretical emphasis, and math minor. He's been developing websites since 2001. After gaining experience designing custom platforms, e-commerce, and automation solutions James joined AmericanEagle.com in 2013, focusing on Sitecore.

When not tinkering with tech, James enjoys playing a good Eurogame with friends.

Write a review