0

Is it possible to add css classes to auto-generated outer div for block element ? I have a simple Block with a ViewModel and a Controller and I need modify this autogenerated outer div, or optionally remove it?

I looked at other answers to this question where it was recommended ie.

@Html.PropertyFor(model => model.CurrentBlock.ClientLogos, new
{
    CustomTag = "ul",
    CssClass = "list",
    ChildrenCustomTagName = "li",
    ChildrenCssClass = "list_item"
})

Problem is when I use this syntax, model has no CurrentBlock property ???

My model is bound to ViewModel, I'm not sure if it affects this. I am very new to Optimizely.

Eric Herlitz
  • 25,354
  • 27
  • 113
  • 157
Jeekim
  • 543
  • 5
  • 15
  • The code indicates that your block is setup as a property directly on your page making it a local block. Are you sure you want this and not using a contentarea instead? – Eric Herlitz May 06 '22 at 17:53

1 Answers1

0

You can use custom tag and css class. In your example CurrentBlock is probably part of the viewModel, you can directly use model.ClientLogs. Alternativly if you want more control you can use editing attributes.

<h1 @Html.EditAttributes(x => x.Heading)>
  /* Render the Heading property, unless it it empty, then use PageName as fallback */
  @Model.Heading ?? @Model.PageName
</h1>

You can find more information about editing attributes here: https://docs.developers.optimizely.com/content-cloud/v11.0.0-content-cloud/docs/adding-editing-attributes-using-property-web-control