This project is read-only.

Finding out if module is enabled from theme

Topics: Customizing Orchard
Dec 9, 2014 at 2:49 AM
Hello all, I have done some searching both here in the forums as well as on the web, but I still have not come up with any useful answers. My question is, from within a view in my theme, how can I go about finding out if a module has been loaded? I have created a "Download" content type, and from within it's view I would like to perform a specific action if the Amba.DownloadsCounter module is enabled. The "Download" content type was created from within the Orchard UI, not from within a module. The Amba.DownloadsCounter module is a contrib module, so I do not want to modify it in any way, so I need to check if it is enabled from within my theme. Thanks for any guidence.
Dec 11, 2014 at 3:55 AM
As a temporary solution, I have worked up the following method to see if the download counter module responds to a request to it's controller, but I don't really feel like this is the best way to handle this situation. Again, any help would be greatly appreciated.
// <summary>
    /// This function is used to check if the Amba.DownloadCounter module URL is valid for a file download link.
    /// </summary>
    /// <param name="url">The base Asp.Net style URL for the item (~/path-to-file)</param>
    /// <returns>True if the Amba.DownloadCounter URL is valid, false if not.</returns>
    bool DownloadCounterEnabled(string url)
            url = Request.Url.GetLeftPart(UriPartial.Authority) + Url.Content(url.Replace("~", "~/download"));
            WebRequest request = WebRequest.Create(url);
        catch (System.Net.WebException)
            return false;

        return true;
Dec 13, 2014 at 4:09 AM
Here, an example that use the feature Id, verify in your module.txt that it's the right feature Id
E.g for the Autoroute feature, the Name is "Autoroute", and the Id is "Orchard.Autoroute"
@using Orchard.Environment.Features
  IFeatureManager _featureManager = WorkContext.Resolve<IFeatureManager>();
  var featureEnabled = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "Amba.DownloadsCounter") != null;
For testing, you can use
  <h1>Test: @featureEnabled</h1>
Marked as answer by DMFirmy on 12/13/2014 at 5:26 PM
Dec 14, 2014 at 1:26 AM
Thank you so much jtkech! This is exactly what I was looking for and it works like a charm. I am much obliged!