ByteEditor Website Builder

Wiki menu

Create layout

By following the steps in this instruction, you will be able to create your custom four-column layout. You can use the code snippets provided in the guide to recreate this layout, or you can modify the steps to tailor the layout to your specific needs.
Screenshot At Oct 29 18 28 28

In order to create a layout, for example, Four Columns Layout, we need a back office preview (a Lit custom view registered in an “umbraco-package.json” file), an element type, and a front-end view.


Step 1. Back office preview

  1. Open the project folder
  2. Open the “App_Plugins” folder
  3. Create a folder for custom layouts, for example, name “CustomBlockView”
  4. Create a file named “four-column-layout.custom-view.js”
  5. Copy the following code and paste it into the file
import { html, nothing, LitElement } from '@umbraco-cms/backoffice/external/lit';
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
import { getGlobalStylesheetHrefs } from '/App_Plugins/UmbracoBlockGrid/BlockViews/shared/global-styles.js';
import { renderGlobalStylesheetLinks } from '/App_Plugins/UmbracoBlockGrid/BlockViews/shared/global-stylesheet-links.js';
import { resolveSingleMedia } from '/App_Plugins/UmbracoBlockGrid/BlockViews/shared/media-resolver.js';
import { getLicenseGateState, renderLicenseBanner } from '/App_Plugins/UmbracoBlockGrid/BlockViews/shared/license-gate.js';

export class FourColumnLayoutCustomView extends UmbElementMixin(LitElement) {
    static properties = {
        content: { attribute: false },
    };

    #stylesheetHrefs = [];
    #backgroundImageUrl;
    #licenseState = { showBanner: false, message: '' };

    // Render into the light DOM so the block uses the site's real Bootstrap and theme classes.
    createRenderRoot() {
        return this;
    }

    willUpdate(changedProperties) {
        if (changedProperties.has('content')) {
            this.#loadData();
        }
    }

    async #loadData() {
        const [licenseState, media, stylesheetHrefs] = await Promise.all([
            getLicenseGateState(this),
            resolveSingleMedia(this, this.content?.backgroundPicture, 'rmode=min&width=1920'),
            getGlobalStylesheetHrefs(this),
        ]);
        this.#licenseState = licenseState;
        this.#backgroundImageUrl = media?.url;
        this.#stylesheetHrefs = stylesheetHrefs;
        this.requestUpdate();
    }

    render() {
        const variantValue = this.content?.themeVariant;
        const variant = (Array.isArray(variantValue) ? variantValue[0] : variantValue) || 'base';
        const paddingTop = this.content?.addMarginToTheTop === false ? 'pt-0' : 'pt-5 pt-md-7 pt-lg-8';
        const paddingBottom = this.content?.addMarginToTheBottom === false ? 'pb-0' : 'pb-5 pb-md-7 pb-lg-8';
        const style = this.#backgroundImageUrl ? `background-image: url('${this.#backgroundImageUrl}')` : nothing;

        return html`
            ${renderGlobalStylesheetLinks(this.#stylesheetHrefs)}
            <section
                class="be-preview be-v-${variant} be-v-reset four-col-section ${paddingTop} ${paddingBottom} ${this.content?.customCssClasses ?? ''}"
                data-bs-theme="light"
                style=${style}>
                ${renderLicenseBanner(this.#licenseState)}
                <umb-block-grid-areas-container></umb-block-grid-areas-container>
            </section>
        `;
    }
}

customElements.define('custom-four-column-layout-view', FourColumnLayoutCustomView);
export default FourColumnLayoutCustomView;

6. Create a file named “umbraco-package.json” in the “CustomBlockView” folder
7. Add the following JSON to the file:

{
  "name": "Custom Block Views",
  "version": "1.0.0",
  "extensions": [
    {
      "type": "blockEditorCustomView",
      "alias": "Custom.BlockGrid.FourColumnsLayout",
      "name": "Four Columns Layout Block View",
      "element": "/App_Plugins/CustomBlockView/four-column-layout.custom-view.js",
      "forContentTypeAlias": "fourColumnsLayoutBlock",
      "forBlockEditor": "block-grid"
    }
  ]
}

💡 There is no build step: Umbraco 17 loads these files directly. “forContentTypeAlias” must match the element type alias you create in Step 2. To learn more, see the Umbraco documentation on custom views for blocks.

Step 2. How to create a layout in Umbraco

  1. Run your project locally where the ByteEditor 17.X package is installed.
  2. Open the “Settings” section.
  3. Expand “Document Types” → “Blocks”.
  4. Hover over the “Layouts” folder, click '...' and choose “Create”.
  5. Select “Element Type”.
  6. Name it “Four Columns Layout”.
  7. Click the icon next to the name and pick an icon for the layout.
  8. Next to the name, change the alias from “fourColumnsLayout” to “fourColumnsLayoutBlock”.
  9. Click “Add group” and name the group “Content”.
  10. Click “Add property”, name it “Background picture” (alias “backgroundPicture”).
  11. Click “Select property editor” and choose “Image Media Picker”, then “Submit”.
  12. Click “Compositions”.
  13. Under “Blocks/Compositions”, select “Section Margins”, “Section Settings” and “Section Custom CSS for elements”.
  14. Click “Submit”, then “Save”.
Дизайн Без Названия (7)

Step 3. How to add Layout to the Block Grid

  1. Open “Settings” → “Data Types” → “Home - Main Grid - Block Grid”.
  2. Click “Add block” and choose “Four Columns Layout”.
  3. Put it in the “Layout” group.
  4. Turn on “Allow at root” and turn off “Allow in areas”.
  5. Open “Areas” and add four areas with the aliases “first”, “second”, “third” and “fourth”, each 3 columns wide.
  6. Click “Submit”, then “Save”.

💡 Unlike Umbraco 13, there is no “Custom view” field on the block: the preview is picked up automatically from “umbraco-package.json” by the element type alias.

Дизайн Без Названия (8)

Step 4. How to create a Layout view on the front end

  1. In “Settings”, expand “Partial Views” → “blockgrid”.
  2. Hover over the “Components” folder, click '...' and choose “Create” → “Empty partial view”.
  3. Name it “fourColumnsLayoutBlock.cshtml”.
  4. Copy the following code and paste it into the file
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockGridItem<FourColumnsLayoutBlock>>
@using Umbraco.Cms.Core.Models
@{
    var image = Model.Content.BackgroundPicture;
    var paddingTopClass = Model.Content.AddMarginToTheTop ? "pt-5 pt-md-7 pt-lg-8" : "pt-0";
    var paddingBottomClass = Model.Content.AddMarginToTheBottom ? "pb-5 pb-md-7 pb-lg-8" : "pb-0";
    var themeVariantClass = $"be-v-{Model.Content.ThemeVariant.IfNullOrWhiteSpace("base")} be-v-reset";
}
<section class="@paddingTopClass @paddingBottomClass four-col-section @Model.Content.CustomCssClasses @themeVariantClass" style="color: var(--bs-body-color); @(image != null ? $"background-image: url({image.GetCropUrl(imageCropMode: ImageCropMode.Min, width: 1920)});" : "")">
    @await Html.GetBlockGridItemAreasHtmlAsync(Model)
</section>

5. Click “Save”
6. Restart the project so ModelsBuilder generates the “FourColumnsLayoutBlock” model


Congratulations!

You have created your first layouts. Now you can add it to your page and fill with the elements. 


The result of the work done!

Дизайн Без Названия (10)
Built with ByteEditor