Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • bikeman 12 posts 93 karma points
    Aug 04, 2020 @ 16:21
    bikeman
    0

    Using an alternative css grid system, creating a custom renderer

    Hi,

    I want to use an alternative CSS framework to Bootstrap or Foundation.

    All I can find is this article which explains how to create a property alias to path to a custom renderer.

    https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Grid-Layout/Render-Grid-In-Template

    This is obviously insufficient.

    Is there actually a guide to creating a custom renderer?

  • Chris Evans 112 posts 283 karma points c-trib
    Aug 05, 2020 @ 03:01
    Chris Evans
    0

    To get the Grid to output your own custom HTML, rather than the default Bootstrap structure, you can add a new partial view in the /Views/Partials/Grid folder and then tell your Html.GetGridHtml method to use that view.

    e.g. if you create a new view called CustomGrid.cshtml in /Views/Partials/Grid you can call this on your template:

    @Html.GetGridHtml(Model, "propertyAlias", "CustomGrid")
    

    and the page will output the Grid content using the razor script in CustomGrid.cshtml instead of the default Bootstrap3.cshtml view.

    A good way to get this working is to copy Bootstrap3.cshtml, rename it to your custom name, and change the html tags in the view to be your custom structure, while leaving all the logic in place.

    Alternatively you can use a barebones file like this and encapsulate the output structure in your editor views themselves (i.e. without requiring structural HTML in the renderer):

    @inherits UmbracoViewPage<dynamic>
    @using Umbraco.Web.Templates
    @using Newtonsoft.Json.Linq
    
    @if (Model != null && Model.sections != null)
    {
        foreach (var section in Model.sections)
        {
            foreach (var row in section.rows)
            {
                @renderRow(row, true)
            }
        }
    }
    
    @helper renderRow(dynamic row, bool singleColumn)
    {
        foreach (var area in row.areas)
        {
            foreach (var control in area.controls)
            {
                if (control != null && control.editor != null && control.editor.view != null)
                {                
                    <text>@Html.Partial("grid/editors/base", (object)control)</text>
                }
            }
        }
    }
    

    Using this barebones approach tends to work better if your Grid is configured to only allow single column rows, with the blocks themselves managing any side-by-side or multi-column layouts internally.

  • bikeman 12 posts 93 karma points
    Aug 07, 2020 @ 08:40
    bikeman
    0

    I copied bootstrap3.chtml and renamed it materializcss.cshtml

    Then added @Html.GetGridHtml(Model, "propertyAlias", "materializecss")
    to my master tempalte but got the following error when I added a grid to a page:

    enter image description here

  • bikeman 12 posts 93 karma points
    Aug 07, 2020 @ 09:03
    bikeman
    0

    Secondly, when I do have it using the custom structure, you've not provided any detail on how to amend the html structure.

    I looked at the foundation5 grid for example but it's not apparent how it should change.

    For example, I guess I should be changing the html at

    <div class="row clearfix">
        @foreach (var s in Model.sections)
        {
            <div class="@baseColSize-@s.grid columns">
                @foreach (var row in s.rows)
                {
                    @renderRow(row, baseColSize);
                }
            </div>
        }
    </div>
    

    But the format of foundation html is

    <div class="row">
      <div class="small-2 large-4 columns">...</div>
      <div class="small-4 large-4 columns">...</div>
      <div class="small-6 large-4 columns">...</div>
    </div>
    

    So what maps @baseColSize to 'small' or 'medium' etc?

Please Sign in or register to post replies

Write your reply to:

Draft