0
votes

I am new to developing for Sitecore using MVC. I have a page layout that looks like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    @Html.Sitecore().Placeholder("head-meta-content")
</head>

<body>
    <div class="willow-page">
        @Html.Sitecore().Placeholder("body-content")
    </div>
</body>
</html>

And I have the following renderings.

Global alert:

@using Sitecore.Mvc;
@model Sitecore.Mvc.Presentation.RenderingModel

<section class="global-alert" role="alert">
    <button class="global-
alert__close">@Html.Sitecore().Field("button-text", Model.Item)
</button>
    <h1 class="global-
alert__heading">@Html.Sitecore().Field("heading-text", Model.Item)</h1>
    <div class="global-alert__content">
        @Html.Sitecore().Placeholder("global-alert-content")
    </div>
</section>

Styling Context:

@using Sitecore.Mvc;
@model Sitecore.Mvc.Presentation.RenderingModel

<div class="styling-context">
    @Html.Sitecore().Field("Content", Model.Item)
    <!-- The Content field is should be a Rich Text Field -->
</div>

What I am trying to accomplish/understand is this. When creating a page using the layout and the 2 renderings, I'd like to add the Global Alert to the body-content place holder on the layout and then add a Styling Context to the global-alert-content place holder. Also I'd like to add another Styling Context to the body-content place holder as well. Like this:

Sitecore device editor display for controls

Then when viewing the page content tab in Sitecore, I'd like to see a section with a rich text field for the Global Alert Styling Context & the Body Styling context. I can't seem to figure out how to setup my data to accomplish this.

I've tried to setup the following data templates.

Global Alert Template - Builder

Global Alert Template - Builder

Global Alert Template - Content

Global Alert Template - Content

Notice the _stylingContext in the Base Template area above.

Styling Context - Builder

Styling Context - Builder

Blank Page - Page Template

Blank Page - Page Template

Note the inherited templates above.

The global alert template is pulling in a styling context template, & the page template is pulling a separate styling context template, I would think there'd be 2 on the page. There isn't though.

1
By content tab you mean on the item directly in the content editor, right?Hishaam Namooya
Yes, that is correct. Like this. I would anticipate/like there to be a RTF section for both Styling Contexts.Lisa-J
I didn't quite get you. Can you please update the question to add what you are having and what is expectedHishaam Namooya
I have updated the question, hopefully that will help.Lisa-J
So, if I have understand properly, you are not having the 2 rich text fields but only 1 on the item. Is that correct?Hishaam Namooya

1 Answers

1
votes

This is the normal behavior of Sitecore. The reason is because the same template is being referenced in the Base Template. So, when rendering the item, Sitecore will see that the template has already been rendered and will not render it again.

If template A has Base Template X and X has Base Template Y, it is not possible to have template A to have Y as base template also.

A => X
X => Y
which means A => Y

To allow for the 2 Rich Text to appear, you can do the following:

  1. Create a Base Styling Context

enter image description here

  1. On your template Styling Context, add your Content Field of type Rich Text in the Builder tab and in the Content tab, add the Base Styling template.

enter image description here

  1. On your Global Alert template, in the Content tab, add the Styling Context template.

enter image description here

  1. On your blank Page template, add the Global Alert only and not the Styling Context.

enter image description here

Now if you see on the Standard Values of the Blank Page template, you will see 2 rich text fields with the same field name within the same section:

enter image description here