Custom layout resolver

Sitecore provides you the possibility to implement your own layout resolver if the default one is not enough for you. Basically you can change the layout of a page based on a business logic without changing the item in the database.

If you can’t see the code snippets click here to switch to non-AMP mode!

How to do it?

If you are using Sitecore MVC (I hope you are using) you need to inject the following processors in the following pipelines:

The first processor is changing the file path of the .cshtml but unfortunately it is not enough.

You also need to change the layout of the context item to point to the new layout item in Sitecore.

After injecting these 2 processors you should able to change the layout of the context item in the current request. The implementation has been tested on Sitecore 8.2 update 7.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s