Copied to clipboard

Flag this post as spam?

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


  • Marco Lusini 176 posts 1370 karma points
    May 31, 2017 @ 08:55
    Marco Lusini
    0

    Share common @helper with Model Builder in PureLive mode

    Hi,

    I am developing an Umbraco 7.6 site where I have to use PureLive mode for Model Builder.

    Is there a way to share and reuse a common @helper which uses ModeBuilder generated class between different Views/Partialviews?

    If I put it in App_Code folder, it won't compile since the ModelBuilder generated class are not available to the compiler...

    Is there a way to "include" one .cshtml in another?

    TIA,

    /M

  • Søren Kottal 491 posts 3212 karma points MVP 2x c-trib
    Jun 13, 2017 @ 06:12
    Søren Kottal
    0

    Hi Marco

    I have previously been able to add a cshtml named App_Code/MyProject/GlobalHelpers.cshtml.

    In this I had the following:

    @using Umbraco.Web;
    
    @helper RenderBreadcrumb(int id)
    {
        var uh = new UmbracoHelper(UmbracoContext.Current);
        var basenode = uh.TypedContent(id);
        var nodes = basenode.Ancestors().Where(x => x.GetPropertyValue("umbracoBreadcrumbHide") != "1");
    
        <ol class="breadcrumb">
            @foreach (var node in nodes)
            {
                <li><a href="@node.Url">@node.GetPropertyValue("navName", node.Name)</a></li>
            }
            <li class="active">@basenode.GetPropertyValue("navName", basenode.Name)</li>
        </ol>
    }
    

    In my views I could then type:

    @MyProject.GlobalHelpers.RenderBreadcrumb(Model.Content.Id)
    

    And get a breadcrumb.

    Don't know if it works with modelsbuilder though, but you can try!

Please Sign in or register to post replies

Write your reply to:

Draft