Duplicate HTML for responsive views - Placeholders

Duplicate HTML, really?

Last week I got a frontend implementation (HTML/CSS/JS) that wasn't quiet to my liking. It contained duplicate HTML for a component that should be displayed on different locations in the HTML to facilitate correct views on desktop and mobile breakpoints. Time limitations on the project didn't allow for the frontender to find an alternative way of removing this duplication and achieving the same result.
I didn't feel like introducing device views in Sitecore just for this one component.
Luckily the component was in a part of the site that is behind login, so SEO was not a concern.

Not only was the HTML the same for the different views of this component, but also its content needed to be the same, and it needed to have the same personalization.

For a while I wondered on how to support this in the experience editor, without making the 'content editor' change it's browser window to a different responsive view, nor breaking the look of the page while editing by displaying both instances of the HTML while in experience editor mode.

Then I had a thought what would happen if I would just duplicate the placeholder where I put this component in, in two locations of the layout.
It turned out that this works. When you create a second placeholder somewhere else on your layout, with the same name. Your single component is just rendered twice.
This solved all my problems at once:

  • Content editor only needs to maintain the content and personalization in one location
  • I don't have to find work around to make the separate instances content manageable
  • I don't have to worry about content editor forgetting one of the places this component is in, and there fore creating a mismatch in its content over different views



Reacties

Populaire posts van deze blog

I Robot - Sitecore JSS visitor identification

Sitecore campaigns and UTM tracking unified

Sitecore JSS - Sitecore first