Copied to clipboard

Flag this post as spam?

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


  • Arun 127 posts 328 karma points
    1 week ago
    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 1267 posts 3860 karma points MVP 6x c-trib
    1 week ago
    Bjarne Fyrstenborg
    0

    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