'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'RequiresCss' and no extension method 'RequiresCss' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
I've also tried registering the ClientDependency assembly in the web.config in the hope that that might expose its extensions, but no joy.
I've found code for rendering the output of the ClientDependency framework using a razor macro (all of which seem to ultimately derive from the code in the uBootstrap package), but I haven't found a single macro that registers a file with the framework. Seems like a core bit of Umbraco functionality that I'd expect to be exposed by default and well documented, but it would appear not, so is this something that's simply impossible or just so convoluted no-one bothers?
You are correct - the razor examples given for registering resources will only work in MVC. But, assuming that you have registered and added the ClientDependencyLoader to your template/masterpage like so:
One other thing to be aware of is that, in the given state of Umbraco (up to 4.10), if you _cache_ such a macro then the code for it will run _once_ and then the result will be cached. The result is the HTML markup only -- _not_ whatever dependencies you registered. In other words, when the macro is served from the cache, the dependencies will _not_ be registered.
Hi guys, trying to get @Douglas Ludlow's approach to work in a 4.10 site, the straight forward entires in the masterpage template work, but for the life of me I can't get any razor code to work
First Off ClientDependencyLoader.Instance is now obsolete,
so we have ClientDependencyLoader.GetInstance(Context) but that always gives a null reference exception.... any ideas? As if we can't get razor to inject into the ClientDependancyLoader then we can't really use it full stop.
Firstly - Douglas, please accept my apologies for very rudely not getting back to you a great deal earlier. This work is on our own website and it's inevitably been pushed aside by client work.
Yes, your code is working for me - thanks a lot.
Mike - Douglas' code works for me, as does replacing ClientDependencyLoader.Instance with ClientDependencyLoader.GetInstance(Context) - however, this site is on Umbraco 4.9, not 4.10.
For the record, this is the code I've ended up with:
Whilst this works... move the <umb:UmbracoClientDependencyLoader runat="server" ID="ClientLoader" /> any lower than the injecting macro and it fails, with
Error Loading Razor Script (file: Inject CDL) Object reference not set to an instance of an object. at ASP._Page_macroScripts_injectCDL_cshtml.Execute() in e:\WebDevelopment\15006_jpt\v10\u4111.dev.fidus.co.uk\LiveSite\macroScripts\injectCDL.cshtml:line 4 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
Which is a bit of a showstopper as far as practical use of this goes...
I wonder if there's any other way to register loaders? i.e. are the ClientDependencyLoader and the PageHeaderProvider the only loaders you can declare, or is it possible to add something else which could control the location of the insertion point? There's nothing in the documentation, but then as far as I can see that page is the only one that even mentions the PageHeaderProvider, and then it just seems to assume you know about it! There's an (unanswered) comment at the bottom referring to PlaceHolderProvider, which sounds promising but it looks like if you want to know more you're going to have to trawl through the source code...
Using ClientDependency Framework from a Razor Macro
Hi,
This seems like something that ought to be dead straightforward - but so far I've not managed to figure this out or find a working example...
I'm trying to register CSS and JavaScript files with the ClientDependency framework, from an Umbraco 4.9 razor macro.
The ClientDependency docs
http://clientdependency.codeplex.com/wikipage?title=MVCFileRegistration&referringTitle=Documentation
and this
http://www.enkelmedia.se/blogg/2012/9/1/umbraco-och-client-dependency-framework.aspx
give razor examples for the ClientDependency framework, but I suspect only for a full MVC structure not simple razor macros.
I came up with this as a possible solution:
But this simply reports:
'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'RequiresCss' and no extension method 'RequiresCss' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
I've also tried registering the ClientDependency assembly in the web.config in the hope that that might expose its extensions, but no joy.
I've found code for rendering the output of the ClientDependency framework using a razor macro (all of which seem to ultimately derive from the code in the uBootstrap package), but I haven't found a single macro that registers a file with the framework. Seems like a core bit of Umbraco functionality that I'd expect to be exposed by default and well documented, but it would appear not, so is this something that's simply impossible or just so convoluted no-one bothers?
Geoff
Hey Geoff,
You are correct - the razor examples given for registering resources will only work in MVC. But, assuming that you have registered and added the ClientDependencyLoader to your template/masterpage like so:
You should be able to register resources within your razor scripts in the following manner:
Alternatively, you can use the following methods to add external resources:
However, you won't get the benefit of ClientDependency's bundling and minification.
Hope that helps!
It might be worth noting that there are a number of overloads to the RegisterDependency() method, such as:
Did that help at all?
One other thing to be aware of is that, in the given state of Umbraco (up to 4.10), if you _cache_ such a macro then the code for it will run _once_ and then the result will be cached. The result is the HTML markup only -- _not_ whatever dependencies you registered. In other words, when the macro is served from the cache, the dependencies will _not_ be registered.
Hi guys, trying to get @Douglas Ludlow's approach to work in a 4.10 site, the straight forward entires in the masterpage template work, but for the life of me I can't get any razor code to work
First Off ClientDependencyLoader.Instance is now obsolete,
so we have ClientDependencyLoader.GetInstance(Context) but that always gives a null reference exception.... any ideas? As if we can't get razor to inject into the ClientDependancyLoader then we can't really use it full stop.
Hi,
Firstly - Douglas, please accept my apologies for very rudely not getting back to you a great deal earlier. This work is on our own website and it's inevitably been pushed aside by client work.
Yes, your code is working for me - thanks a lot.
Mike - Douglas' code works for me, as does replacing ClientDependencyLoader.Instance with ClientDependencyLoader.GetInstance(Context) - however, this site is on Umbraco 4.9, not 4.10.
For the record, this is the code I've ended up with:
Found my issue...
If you move the
so that positionally it is below the razor macro in the template html when you try to insert the dependency it errors.
eg this fails
but this works
A page cycle instantiation issue?
I can't see a way around this to have JS added in the foot of the page, but css in the header....
Hi Mike,
Is this thread any help? It sounds like there may still be some issues, but the last post is a few months old they they may be fixed by now.
Documentation here.
I'll have to have a play with this myself!
Geoff
Thanks Geoff that was what I was aiming for... but was back tracking to find out why I'm getting errors trying to inject into the loader from razor...
So, as simple as it gets
template
and the inhectCDL
Whilst this works... move the <umb:UmbracoClientDependencyLoader runat="server" ID="ClientLoader" /> any lower than the injecting macro and it fails, with
:-(
Which is a bit of a showstopper as far as practical use of this goes...
I wonder if there's any other way to register loaders? i.e. are the ClientDependencyLoader and the PageHeaderProvider the only loaders you can declare, or is it possible to add something else which could control the location of the insertion point? There's nothing in the documentation, but then as far as I can see that page is the only one that even mentions the PageHeaderProvider, and then it just seems to assume you know about it! There's an (unanswered) comment at the bottom referring to PlaceHolderProvider, which sounds promising but it looks like if you want to know more you're going to have to trawl through the source code...
Geoff
is working on a reply...