Sitecore 9 - Dynamic Placeholders
Let's first understand the concept. Let's assume you want to use a placeholder with 2 different component on same page. I am going to create the Items based on below details. I am following the basic details, which is needed to create dynamic placeholders.
- Create placeholder settings Item (settings name: 2 Column Component PS Settings) for your placeholder (placeholder key: "content-row-2-col")
- Add 2 Column Component in your Placeholder Settings Allowed Controls. and publish it.
- Open your page in Experience Editor
- Click inside main-content placeholder >> Add Here >> Select 2 Column Component
- Add data sources for Image tile 1 and 2.
- Click again inside main-content placeholder >> Add Here >> Select 2 Column Component
- You'll see 2 Column Component is repeating in with same data sources.
Here you comes with Dynamic Placeholder
- Change your view.cshtml file and modify you placeholder to dynamic placeholder.
- you can use this code @Sitecore().DynamicPlaceholder("content-row-2-col")
- publish your cshtml file and Reload Experience Editor.
- Click inside main-content placeholder >> Add Here >> Select 2 Column Component
- Add data sources for Image tile 1 and 2.
- Click inside main-content placeholder >> Add Here >> Select 2 Column Component
- Add data sources for Image tile 3 and 4.
- Publish and view your page
- Now you'll see both Components are rendered in accordance to your selection in Placeholder.
Let me know your feedbacks.
Hope you enjoyed it !! 😊
Comments
Post a Comment