Copied to clipboard

Flag this post as spam?

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


  • Nigel Wilson 945 posts 2077 karma points
    Mar 31, 2013 @ 09:24
    Nigel Wilson
    0

    MVC and Client Dependency in V4.11.5

    Hi there

    I have just started using Client Dependency with Web Forms - a bit behind the times, but definitely appreciate the functionality.

    Now I decide to try my hand at MVC for Umbraco, and want to utilise Client Dependency, but so far without success.

    I now have 2 issues:
    Firstly and most importantly, how to get Client Dependency working - current code provided below:

    Secondly, within web forms I had 2 sets of Client Dependency code - one set in the head and one set at the end of the page for speed optimisation. Is this achieveable within MVC ?

    And so onto my code - this is what I have in my Master.cshtml view page

     

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using ClientDependency.Core
    @using ClientDependency.Core.Mvc
    @{
        Layout = null;
        Html.RequiresCss("/css/base.css", "Styles").RequiresCss("/css/skeleton.css", "Styles").RequiresCss("layout.css", "Styles").RequiresJs("/scripts/jquery-1.9.1.min.js");
        var homepage = Model.Content.AncestorOrSelf(1);
    }
    ... Other code here ... @Html.Raw(Html.RenderCssHere()) @Html.Raw(Html.RenderJsHere())

     

    I downloaded and added the Mvc dll file from http://clientdependency.codeplex.com/ and placed it in the bin.

    The HTML output is simply some comments as below:

    <!--[Css:Name="StandardRenderer"]//-->
    <!--[Javascript:Name="StandardRenderer"]//-->

    Can anyone assist please ?

    Thanks, nigel

     

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Jun 05, 2013 @ 17:38
    Peter Gregory
    0

    Im after the same info regarding specifying multiple render locations. I am also getting the strange output. 

    &lt;!--[Css:Name=&quot;StandardRenderer&quot;]//--&gt;

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Jun 06, 2013 @ 03:17
    Peter Gregory
    1

    With a whole bunch of help from Shannon and upgrading to v1.7.0.3 https://nuget.org/packages/ClientDependency-Mvc/1.7.0.3 I was about to get the CDF working the way that I wanted in 6.1.1

    With v1.7.0.3 you dont need to do the @Html.Raw around the renderers anymore which is nice. Also note that the config examples shipped with Umbraco are not 100% correct but are going to be fixed in a future release.

    So to get multiple locations you need to update the clientdependency.config file to have a custom renderer for the other locations.

    Towards the bottom of the file there is a commented section that you will need to uncomment.

      <mvc defaultRenderer="StandardRenderer">
       <renderers>
    <add name="StandardRenderer" type="ClientDependency.Core.FileRegistration.Providers.StandardRenderer, ClientDependency.Core" enableCompositeFiles="true"/>
    <add name="HeadRenderer" type="ClientDependency.Core.FileRegistration.Providers.StandardRenderer, ClientDependency.Core" enableCompositeFiles="true"/>
    <!--<add name="LazyLoadRenderer" type="ClientDependency.Core.Mvc.Providers.LazyLoadRenderer, ClientDependency.Core"/>-->
       </renderers>
    </mvc>

    The standardRenderer is the one that ships by default and is what is used for @Html.RenderJsHere() and @Html.RenderCssHere()

    The HeadRenderer is my custom one that allows me to create a new renderer for Js and Css somewhere else in my layouts.

    So to use this you will need to say where you want your scripts by doing this.

    @Html.RenderJsHere("HeadRenderer")

    Just specify the renderer that you want to use as a string matching your config.

    Then when you want to inject something into that Renderer do the following

    @{Html.RequiresJs(new JavascriptFile("~/scripts/somescript.js") { ForceProvider = "HeadRenderer" });} 

    And thats it!  You should now be able to create as many Renderers as you need.  Shannon has created feature request for in the future to not have to specify any configuration and to make it easy to just create new Renderer sections by providing a string key.

    Docs for CDF can be found here https://github.com/Shandem/ClientDependency/wiki 
    Information on config can be found here https://github.com/Shandem/ClientDependency/wiki/Configuration 
    Information on forcuing providers and renderers can be found here https://github.com/Shandem/ClientDependency/wiki/Forced-Providers

Please Sign in or register to post replies

Write your reply to:

Draft