Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesRazor + Page Object + Script InsertionRazor + Page Object + Script Insertion
Previous
 
Next
New Post
1/25/2014 10:49 AM
 

Hi Brad

I know its late to reply but I've just been trying to do something similar this afternoon. I wanted to check to see if the client resource manager had already add a CSS file or not. 

As you say DNN fail to explain how to reference the Page object which you would get in a Webform page. Without this reference to the object the razor scripts are limited. 

The solution is pretty simply once you start digging into the sourcecode and use ILSpy. This is the code I've wrote to get access to the page, then look in the header for the CSS that would have been registered by other modules. If the header with the correct CSS file doesn't exist we just add it from the razor code block. 

The object to use is Context.CurrentHandler then cast is back to the Page. From there its pretty simple code to do the check.


@using DotNetNuke.Web.Client.ClientResourceManagement;

@{
var p2 = Context.CurrentHandler as Page;

bool foundTarget = false;
string cssName = "/Portals/0/CVStore/ResponsiveTemplates/StyleSheet/font-awesome.min.css";

foreach(var c in p2.Header.Controls){

var headerCss = c as DnnCssInclude;
if(headerCss != null){
if(headerCss.FilePath == cssName.ToLower()){
foundTarget = true;
}
}
}

if(!foundTarget){
ClientResourceManager.RegisterStyleSheet(p2, cssName);
}
}

 


Visit www.bitethebullet.co.uk for more free DNN modules and tutorials
 
New Post
8/7/2014 2:45 PM
 
Mark McAvoy wrote: @{ var p2 = Context.CurrentHandler as Page; } }

Okay, so I haven't logged onto these forms in probably 5 years or so, but I had to login to say thank you for this little DNN Razor gem!

DNN should really embrace Razor more and include more core Helpers EditUrl() begin one of the most obvious ones

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesRazor + Page Object + Script InsertionRazor + Page Object + Script Insertion


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out