Wiki menu

Create element

Following these instructions, you can create a new card for your elements gallery. You can recreate this element using the code snippets provided in the guide, or modify the steps to tailor it to your specific needs.

Expected result

Values

In order to create a new card, for example, Four Columns Layout, we need a back office view, a controller, and a front view 


Step 1. Basic changes to the code

  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 test document named “cardWithIconCenteredBlock.html”
  5. Please copy the following code and paste it into the file
<div class="card-feature-sm card-border-radius text-break d-flex flex-column align-items-center" ng-class="{'p-5':  design.baselineColors !== design.getStyle(block.data.backgroundColor)}" ng-controller="cardWithIconCenteredBlockController" ng-style="{
'--bs-btn-primary-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).button.text : '',
'--bs-btn-primary-bg': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).button.fill : '',
'--bs-btn-primary-border-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).button.stroke : '',
'--bs-btn-primary-hover-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).button.textHover : '',
'--bs-btn-primary-hover-bg': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).button.fillHover : '',
'--bs-btn-primary-hover-border-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).button.strokeHover : '',

'--bs-btn-primary-outline-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).buttonSecondary.text : '',
'--bs-btn-primary-outline-border-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).buttonSecondary.stroke : '',
'--bs-btn-primary-outline-hover-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).buttonSecondary.textHover : '',
'--bs-btn-primary-outline-hover-bg': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).buttonSecondary.fillHover : '',
'--bs-btn-primary-outline-hover-border-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).buttonSecondary.strokeHover : '',

'--bs-heading-h1-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.h1 : '',
'--bs-heading-h2-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.h2 : '',
'--bs-heading-h3-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.h3 : '',
'--bs-heading-h4-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.h4 : '',
'--bs-heading-h5-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.h5 : '',
'--bs-heading-h6-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.h6 : '',
'--bs-border-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.border : '',
'--bs-link-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.link : '',
'--bs-link-hover-color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.linkHover : '',
'--bs-secondary-rgb': design.baselineColors !== design.getStyle(block.data.backgroundColor)? toRgbString(design.getStyle(block.data.backgroundColor).content.secondary) : '',
'color': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.primary : '',
'background': design.baselineColors !== design.getStyle(block.data.backgroundColor)? '#' + design.getStyle(block.data.backgroundColor).content.background : '',
}" ng-click="block.edit()" ng-focus="block.focus">
<style ng-bind="styles"></style>
    {{mediaItem = (block.data.image[0].mediaKey | mediaItemResolver); ""}}
<div class="img-holder mb-4" ng-if="mediaItem !== null">
<img ng-class="{'feature-icon-svg': mediaItem.properties[0].config.fileExtensions[0].value === 'svg'}" ng-src="{{mediaItem.mediaLink}}?rmode=min&width=96" draggable="false" alt="{{mediaItem.name}}">
</div>
<h3 class="h5 mb-3">{{block.data.headline}}</h3>
<div class="text-holder">
<p ng-bind-html="block.data.richText.markup | safe_html"></p>
</div>
<a class="btn d-inline-block btn-md mt-4" ng-class="{
           'btn-primary': block.data.variant === 'Primary' || block.data.variant === '' || block.data.variant === undefined,
           'btn-outline-primary': block.data.variant === 'Secondary'
       }" ng-if="block.data.link[0].name">{{block.data.link[0].name}}</a>
</div>

6. Create a test document named “cardWithIconCenteredBlock.сontroller.js”
7. Copy the following code and paste it into the file 

angular.module("umbraco").controller("cardWithIconCenteredBlockController", function ($scope, globalDesignService, editorState) {
    $scope.styles = ``;

    if ($scope.block.data.additionalFeatures) {
        globalDesignService.sortAndWatch('additionalFeatures', $scope);
    }

    globalDesignService.getDesignSettings(editorState.getCurrent().id).then(function (design) {
        $scope.selectedBackground = design.baselineColors.background;
        $scope.design = design;
        $scope.$watch('block.data.backgroundColor', function (newValue) {
            $scope.style = design.getStyle(newValue);
        });

        $scope.toRgbString = function (color) {
            return globalDesignService.hexToRgb(color)?.rgbString
        }

        const getFontStyles = (elementType) => {
            return `  
                font-size: ${design.typography[elementType].desktop}px;  
                font-family: ${design.typography[elementType].font.fontFamily}, ${design.typography[elementType].font.fontCategory};  
                font-weight: ${design.typography[elementType].font.fontWeight};  
                font-style: ${design.typography[elementType].font.fontStyle};  
            `;
        };

        const ds = design.dropShadow.cards;
        $scope.styles = ` 
            .lead-lg{
                font-size: ${design.typography.text.desktop + 4}px;  
            }

            .lead-md{
                font-size: ${design.typography.text.desktop}px;  
            }

            .lead-sm{
                font-size: ${design.typography.text.desktop - 2}px;  
            }

            .btn, .btn.btn-sm, .btn.btn-lg{
                font-family: ${design.typography.button.font.fontFamily}, ${design.typography.button.font.fontCategory};
                font-weight: ${design.typography.button.font.fontWeight};
                font-style: ${design.typography.button.font.fontStyle};
                border-radius: ${design.cornerRadius.buttons}px; 
            }

            .body-font-style {
                ${getFontStyles('text')}
            }

            .card-box-shadow{
                box-shadow: ${ds.offsetX}px ${ds.offsetY}px ${ds.blurRadius}px rgba(${globalDesignService.hexToRgb(ds.color).rgbString}, ${ds.opacity}%);
            }

            .border-radius{
                border-radius: ${design.cornerRadius.picturesAndVideo}px; 
            } 

            .card-border-radius{
                border-radius: ${design.cornerRadius.cards}px; 
            }

            h1, .h1 { ${getFontStyles('h1')} }
            h2, .h2 { ${getFontStyles('h2')} }
            h3, .h3 { ${getFontStyles('h3')} }
            h4, .h4 { ${getFontStyles('h4')} }
            h5, .h5 { ${getFontStyles('h5')} }
            h6, .h6 { ${getFontStyles('h6')} }
        `
    });
}); 

8. Go to the Umbraco website
9. Create a test document named “package.manifest” in the “CustomBlockView” folder.
10. Add the following JSON to the package.manifest file:

{
  "javascript": [
    "~/App_Plugins/CustomBlockView/cardWithIconCenteredBlock.сontroller.js"    
  ]  
}
Дизайн Без Названия (6)

Step 2. How to create a element in Umbraco

1. Run your project locally where the “ByteEditor Site Builder 1.X” package is installed.
2. Open the tab “Settings”.
3. Expand the Document Types folder.
4. Hover over the "Blocks" folder in the content tree you will see this icon '...'. Click the icon '...'. 
5. Click the “Create” button.
6. Select “Element type” from the list.
7. Name the "Сard With Icon Centered" block.
8. Add an icon for the layout.
9. On the right side, next to the “lock” icon, change the text from “cardWithIconCentered” to “cardWithIconCenteredBlock”.
10. Click on the "Add groups" button 
11. Name the group “Content”
12. Click on the "Add property" button 
13. Name the property “Image”
14. Click on the "Select editor" button
15. Select “Feature-Icon-Media Picker” from the list
16. Click on the "Submit" button
17. Click on the "Add property" button 
18. Name the property “Headline”
19. Click on the "Select editor" button
20. Select “Textbox” from the list
21. Select “Textstring” from the list
22. Select “Field is required” for the Validation slider
23. Click on the "Submit" button
24. Click on the "Add property" button 
25. Name the property “Rich Text”
26. Click on the "Select editor" button
27. Select “Features List - Features - Rich Text Editor” from the list
28. Click on the "Submit" button
24. Click on the "Add property" button 
25. Name the property “Rich Text”
26. Click on the "Select editor" button
27. Select “Features List - Features - Rich Text Editor” from the list
28. Select “Field is required” for the Validation slider
29. Click on the "Submit" button
30. Click on the "Add property" button 
31. Name the property “Link”
32. Click on the "Select editor" button
33. Select “Feature - Link - Multi URL Picker” from the list
34. Click on the "Submit" button
35. Click on the "Add property" button 
36. Name the property “Button Variant”
37. Click on the "Select editor" button
38. Select “Button - Variant - Radio button list” from the list
39. Click on the "Submit" button
40. On the right side of the screen, find the “Compositions” button and click on it.
41. Scroll to the “/Blocks/Compositions/” block
42. Select the “Section Settings” checkboxes 
43. Click on the "Submit" button
44. Click on the "Save" button

Step 3. How to add element to the Block Grid

  1. Open the Block Grid page
  2. Click on the “Content” block
  3. Click the "Edit" button for  "Home - Main Grid - Block Grid" 
  4. Click the “Add block” button 
  5. Choose "Сard With Icon Centered" from the list
  6. Make the “Allow in root” field inactive
  7. Specify the card size 3, 4, and 6 
  8. Click the " Advanced" button 
  9. Add the path to the .html file for the Custom view field 

    ~/App_Plugins/CustomBlockView/cardWithIconCenteredBlock.html

  10. Add the path to the .css file for the “Custom stylesheet” field 

    ~/css/index.min.css

  11. Save your changes 

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

  1. Expand the "Partial Views" folder.
  2. Expand the "blockgrid" folder.
  3. If you hover over the "Components" folder in the content tree, you will see this icon: '...'. Click the icon.
  4. Select “New empty partial view” from the list.
  5. In the name field, write “cardWithIconCenteredBlock.cshtml
  6. Please copy the following code and paste it into the file
@using PageBuilder.Core.Infrastructure.Helpers
@using Umbraco.Cms.Core.Models
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockGridItem<CardWithIconCenteredBlock>>
@{
    var design = ViewData["Design"] as Design;
    var style = DesignHelper.GetBackgroundColor(Model.Content.BackgroundColor, design?.BaselineColors, design?.Styling);
    var noBackgroundColor = style != design?.BaselineColors;
}
<div class="card-feature-sm card-border-radius text-break d-flex flex-column align-items-center @(noBackgroundColor ?  "p-5": "")"
style="
@(style != design?.BaselineColors ? $"--bs-heading-h1-color: {@style.Content.H1};" : null)
@(style != design?.BaselineColors ? $"--bs-heading-h2-color: {@style.Content.H2};" : null)
@(style != design?.BaselineColors ? $"--bs-heading-h3-color: {@style.Content.H3};" : null)
@(style != design?.BaselineColors ? $"--bs-heading-h4-color: {@style.Content.H4};" : null)
@(style != design?.BaselineColors ? $"--bs-heading-h5-color: {@style.Content.H5};" : null)
@(style != design?.BaselineColors ? $"--bs-heading-h6-color: {@style.Content.H6};" : null)
@(style != design?.BaselineColors ? $"--bs-border-color: {@style.Content.Border};" : null)
@(style != design?.BaselineColors ? $"--bs-link-color: {@style.Content.Link};" : null)
@(style != design?.BaselineColors ? $"--bs-link-hover-color: {@style.Content.LinkHover};" : null)
@(style != design?.BaselineColors ? $"--bs-secondary-rgb: {@Html.HexToRgb(@style.Content.Secondary)?.RgbString};" : null)
@(style != design?.BaselineColors ? $"color: {@style.Content.Primary};" : null)
@(style != design?.BaselineColors ? $"background-color: {@style.Content.Background};" : null)

@(style != design?.BaselineColors ? $"--bs-btn-primary-color: {@style.Button.Text};" : null)
@(style != design?.BaselineColors ? $"--bs-btn-primary-bg: {@style.Button.Fill};" : null)
@(style != design?.BaselineColors ? $"--bs-btn-primary-border-color: {@style.Button.Stroke};" : null)
@(style != design?.BaselineColors ? $"--bs-btn-primary-hover-color: {@style.Button.TextHover};" : null)
@(style != design?.BaselineColors ? $"--bs-btn-primary-hover-bg: {@style.Button.FillHover};" : null)
@(style != design?.BaselineColors ? $"--bs-btn-primary-hover-border-color: {@style.Button.StrokeHover};" : null)

@(style != design?.BaselineColors ? $"--bs-btn-primary-outline-color: {@style.ButtonSecondary.Text};" : null)
@(style != design?.BaselineColors ? $"--bs-btn-primary-outline-border-color: {@style.ButtonSecondary.Stroke};" : null)
@(style != design?.BaselineColors ? $"--bs-btn-primary-outline-hover-color: {@style.ButtonSecondary.TextHover};" : null)
@(style != design?.BaselineColors ? $"--bs-btn-primary-outline-hover-bg: {@style.ButtonSecondary.FillHover};" : null)
@(style != design?.BaselineColors ? $"--bs-btn-primary-outline-hover-border-color: {@style.ButtonSecondary.StrokeHover};" : null)
">
    @{
        var image = Model.Content.Image;
        if (image is not null)
        {
            var altText = image.Value<string>("altText");
            if (string.IsNullOrWhiteSpace(altText))
            {
                altText = image.Name;
            }
<div class="img-holder mb-4">
<img class="@(image.Value<string>("umbracoExtension") == "svg" ? "" : string.Empty)" src="@image.GetCropUrl(imageCropMode: ImageCropMode.Min, width: 96)" alt="@altText">
</div>
        }
    }
<h3 class="h5 mb-3">@Model.Content.Headline</h3>
<div class="text-holder">
        @Model.Content.RichText
</div>
    @if (!string.IsNullOrWhiteSpace(Model?.Content?.Link?.Name))
    {
<a class="btn d-inline-block @(Model.Content.Variant == "Secondary" ? "btn-outline-primary" : "btn-primary") btn-md mt-4" href="@Model.Content.Link.Url" target="@Model.Content.Link.Target">@Model.Content.Link.Name</a>
    }
</div>

7. Click on the "Save" button
8. Restart the project 

Create Element 4

Congratulations!

You have created your first element. Now you can add it to your design.