Client CraftClient Craft HubStart free

Render base styles with `<ccvb-block>`

On this page
Updated 24 Nov 20262 min read

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.

Plan: Free Visual Builder package

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 #

Step by step #

  1. 1
    Register the tag helpersAdd this line to Views/_ViewImports.cshtml:
    razor
    1@addTagHelper *, ClientCraft.VisualBuilder.Umbraco
  2. 2
    Wrap the block viewPut the view's content inside <ccvb-block> and pass the block as block:
    razor
    1@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockGridItem<QuoteBlock>>
    2
    3<ccvb-block block="Model" tag="section">
    4 <blockquote>@Model.Content.Quote</blockquote>
    5 <p class="quote-author">@Model.Content.Author</p>
    6</ccvb-block>

    QuoteBlock is your ModelsBuilder model for the block's content type.

  3. 3
    Render the page stylesheet onceIn the layout's <head>, render the Visual Builder styles once:
    razor
    1<ccvb-assets />
  4. 4
    Check the outputSet a padding on the block in the builder and look at the public page: the section carries the style, and your markup inside is unchanged.

Attributes #

AttributeValue
blockThe block, a BlockGridItem (Model in a Block Grid component view)
tagOptional 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:

razor
1<article class="card" ccvb-style="Model">
2 <h3>@Model.Content.Title</h3>
3</article>
AttributeApplies
ccvb-styleThe block's styles (same as <ccvb-block>)
ccvb-stylesheetOnly the block's stylesheet, without marking the element
ccvb-placementThe block's placement in the grid
ccvb-layoutThe block's layout (display, direction, gaps)
ccvb-layout-scopeThe layout scope for the block's children
ccvb-mediaThe media styles of the block

Each takes a BlockGridItem.

NoteThe tag helper takes a 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.

Was this article helpful?