Copied to clipboard

Flag this post as spam?

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


  • TempleClause 32 posts 248 karma points
    Jun 29, 2017 @ 15:15
    TempleClause
    0

    Writing Code to section from RenderTemplate

    I have the DocumentType Page which is allowed to have TextSection and ImageSection. Each DocumentType has its own template.

    So there is Page.cshtml, TextSection.cshtml, ImageSection.cshtml.

    My Page.cshtml looks like this:

    @foreach (var child in Model.Content.Children())
    {
        @Umbraco.RenderTemplate(child.Id)
    }
    

    My Page.cshtml uses the MasterTemplate.cshtml as Layout file and contains a section called JS. MasterTemplate.cshtml calls the RenderBody method to render the content of Page.cshtml.

    From within Page.cshtml I can write to the JS section. But from within TextSection and ImageSection I can't. I don't get any errors but it's just not written to the section. I assume this doesn't work because I'm not using the Layout tag on the Section Templates.

    How do I resolve this problem?

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jun 29, 2017 @ 18:13
    Nik
    1

    This is a .Net MVC issue where sub views cannot use the section notations. As of yet, I've not been able to find a work around for that is effective and it annoys me.

    I would love it if someone had a decent solution for this as well!

  • siko 24 posts 77 karma points
    Jul 05, 2017 @ 04:26
    siko
    0

    RenderTemplate is a method to be avoided, according to this!

    Perhaps this strategy will work with:

    @Html.Partial("childsPartialViewName", child)
    

    ?

    Check this out!

Please Sign in or register to post replies

Write your reply to:

Draft