asp.net - Equivalent to Razor Section Helper In Sitecore -


i trying include different scripts on different pages in sitecore , can't seem find way of doing this. in normal mvc project add @section{} helper , use on different partial views specify want scripts in layout view, haven't been able find equivalent way razor helper implemented sitecore. i'd without using place holder, don't want add view in sitecore every time need add script file.

thanks in advance.

the way have setup in current sitecore mvc solution layout has extension method call renderscripts() @ bottom before closing body tag.

@html.renderscripts() 

that extension method looks this:

public static ihtmlstring renderscripts(this htmlhelper htmlhelper)     {        var templates = (from object key in htmlhelper.viewcontext.httpcontext.items.keys                          key.tostring().startswith("_script_")                          select htmlhelper.viewcontext.httpcontext.items[key]).oftype<func<object, helperresult>>()                             .select(template => template(null)).tolist();         foreach (var template in templates)         {             htmlhelper.viewcontext.writer.write(template);         }         return mvchtmlstring.empty;     } 

then on each mvc razor view when want include .js file specific rendering call below @ bottom of file:

        @html.script(         @<script src="@url.content("~/js/custom/orderdetail.js?t=11172015")" type="text/javascript"></script>     ) 

below script extension method:

        public static mvchtmlstring script(this htmlhelper htmlhelper, func<object, helperresult> template)     {         htmlhelper.viewcontext.httpcontext.items["_script_" + guid.newguid()] = template;         return mvchtmlstring.empty;     } 

this has worked out , think trying do.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -