Render base styles with `<ccvb-block>`
On this page
Wrap a Block Grid block view in <ccvb-block> so the styles editors set in the Visual Builder reach the page, without writing any styling code yourself.
After the style opt-in, editors can set spacing, borders, backgrounds and more on your blocks. The <ccvb-block> tag helper renders one element that carries those styles, plus the anchor id and custom classes editors set. Your view only renders the block's content inside it.
Before you start #
- The site is opted in to styles. See Opt a site into Visual Builder styles in code.
- Your block views are Block Grid component views (
Views/Partials/blockgrid/Components/<alias>.cshtml) whose model is aBlockGridItem.
Step by step #
- 1Register the tag helpersAdd this line to
Views/_ViewImports.cshtml:1@addTagHelper *, ClientCraft.VisualBuilder.Umbraco - 2Wrap the block viewPut the view's content inside
<ccvb-block>and pass the block asblock:1@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockGridItem<QuoteBlock>>23<ccvb-block block="Model" tag="section">4 <blockquote>@Model.Content.Quote</blockquote>5 <p class="quote-author">@Model.Content.Author</p>6</ccvb-block>QuoteBlockis your ModelsBuilder model for the block's content type. - 3Render the page stylesheet onceIn the layout's
<head>, render the Visual Builder styles once:1<ccvb-assets /> - 4Check the outputSet a padding on the block in the builder and look at the public page: the
sectioncarries the style, and your markup inside is unchanged.
Attributes #
| Attribute | Value |
|---|---|
block | The block, a BlockGridItem (Model in a Block Grid component view) |
tag | Optional element to render: div (default), section, article, aside, header, footer, nav, main, figure or li. Any other value renders div |
On the public page the element gets data-ccvb-block with the block key, the editor's anchor id (unless your markup already sets one) and the editor's custom classes (added to yours). A block without styles renders a plain element, so the wrapper is safe on every block.
Already have an outer element? #
Put the matching attribute on your own element instead of using the wrapper:
| Attribute | Applies |
|---|---|
ccvb-style | The block's styles (same as <ccvb-block>) |
ccvb-stylesheet | Only the block's stylesheet, without marking the element |
ccvb-placement | The block's placement in the grid |
ccvb-layout | The block's layout (display, direction, gaps) |
ccvb-layout-scope | The layout scope for the block's children |
ccvb-media | The media styles of the block |
Each takes a BlockGridItem.
BlockGridItem, so it styles Block Grid blocks. Blocks in a Block List keep their own markup.What happens next #
Point fields at elements with data-property and data-property-node.