Different views for Normal and Experience Editor mode

After some time of using view renderings I began to notice that the code for markup in the view essentially has to be duplicated by dividing the layout for the visitors and the content editor by using of such constuction:

I wanted to have two different views. First one for what the end user of the site will see (visitor), second one – view which is used by the content editor during its work process. And if in case of controller rendering I was happy with such kind of logic:

then in case of using of view rendering resulting ‘crocodile’ made me depressed. And as result of discomfort I felt sprang approach which I want to share with you.

So.

Create template which contains single field – ‘Experience Editor View Path’, for easy of use I put that field in ‘Data’ section.

Further extend the list of base templates of system ‘View rendering’ template with just created one.

In this way now when you create view rendering except of good old ‘Path’ field you have new ‘Experience Editor View Path’ one in which you place path to view which used by content editors working in Experience Editor.