Copied to clipboard

Flag this post as spam?

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


  • Arun 144 posts 407 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 1286 posts 4060 karma points MVP 8x c-trib
    Jan 24, 2023 @ 11:51
    Bjarne Fyrstenborg
    100

    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>
        }
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies