Copied to clipboard

Flag this post as spam?

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


  • Arun 136 posts 369 karma points
    Jan 24, 2023 @ 11:41
    Arun
    0

    Helper function in Umbraco 9+

    Hi Team,
    I was working on a Umbraco 8 project and I have migrated to Umbraco 10.
    There are many templates with @helper function which seems no longer supported.
    Is there any alternative for that?

    Regards

  • Bjarne Fyrstenborg 1281 posts 3991 karma points MVP 8x c-trib
    Jan 24, 2023 @ 11:51
    Bjarne Fyrstenborg
    1

    Hi Arun

    In .NET Core the previous know @helper is just razor functions. https://www.mikesdotnetting.com/article/344/what-happened-to-helpers-in-asp-net-core

    For example:

    @helper RenderList(IEnumerable<string> items, string style){
        <ul>
            @foreach(var item in items)
            {
                <li class="@style">@item</li>
            }
        </ul>
    }
    

    which would now be written as:

    @{
        void RenderList(IEnumerable<string> items, string style) 
        {
            <ul>
                foreach (var item in items)
                {
                    <li class="@style">@item</li>
                }
            </ul>
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft