Get module path from Dojo widget



I've created a Dojo-based addon component, and in order to communicate with the server I've created an AJAX-enabled web service. It resides in a folder called Ajax in the module's root folder, but in order to call it I need to obtain the path to it. Hardcoding the url to something like "http://someserver/modules/MyModule/Ajax/ajax.asmx" would probably work but doesn't feel right. 

So, how can I determine the path to the (public) module folder from my Dojo widget? Is there a JS class similar to the EPiServer.Shell.Paths class that I can use?

Feb 01, 2013 9:12

Hello William.

There are no such helpers on the client side, you can only use server side helper EPiServer.Shell.Paths.ToResource and pass it results to the client side. The way, how it can be passed, depends on how your client component is loaded.

Feb 01, 2013 13:05

Ok, I've followed the pattern described in this article:

The problem is, the widget is loaded by the CMS, and the only server-side code that exists is where the the widget is defined (using the Component attribute). So I don't really see where I would be able to pass the paths info to the client?

Speaking of widgets, how can i define custom CSS for my widget? I have defined the baseClass property in my widget, but how can I import the CSS file? Or do I have to rely on inline styles only?

Feb 01, 2013 13:37

See Stefans blog post about how to load a custom CSS-file:

If you want to load or update data from your component I suggest you go for the REST-approach described in this post:

Here is some documentation about the JSON-REST-store in Dojo:

Edited, Feb 01, 2013 16:23

Well, if you really want to pass some value to the client side, you can define your component on the server side like this (referring to the sample from Linus blog post):

public sealed class CustomComponent : ComponentDefinitionBase
    public CustomComponent()
    : base("alloy.components.CustomComponent")
        PlugInAreas = new [] { PlugInArea.AssetsPanel};
        Categories = new [] {"cms"};
        Title = "My custom component";
        Description = "Shows information about the current content item.";

    public override IComponent CreateComponent()
        Settings["myCustomProperty"] = "MY_SERVER_VALUE";
        return base.CreateComponent();


And whatever you add to the Settings dictionary will be set as a property of your client side component:

) {
    return declare("alloy.components.CustomComponent",
        [_WidgetBase, _TemplatedMixin, _ContentContextMixin], {
            myCustomProperty: null,
            contextChanged: function (context, callerData) {
                if (this.myCustomProperty === "MY_SERVER_VALUE") {


Edited, Feb 01, 2013 17:29

Very helpful, thank you both!

Feb 04, 2013 8:12

There's actually rudimentary client side support for resolving paths in the epi/routes module. It's primarily intended for resolving routes to controllers, but can be used for other purposes as well.

If you declare a route in your module.config like:

  <route url="{moduleArea}/{path}">

You can then use the epi/routes module to resolve server side paths like below:

var path = routes.getActionPath({
  moduleArea: "MyModule",
  path: "path/to/my.aspx"

For more information, have a look at the the module.config documentation.

Feb 04, 2013 10:41

Thanks, I will try that out.

One final question: I've noticed that the epi.cms.widgets.base resource bundle isn't loaded in the dashboard, and thus the method of including custom CSS-files by piggybacking as described in Stefan's blog post doesn't work for my dashboard widget. Is there another resource bundle in dashboard mode that I can piggyback on? 

Feb 05, 2013 13:38

The piggy-backing part described in my blog post is just a way of getting css files into the CMS UI when there are no hooks for pulling the resources in.

If you're creating a component, your client module will be activated as soon as the component is added to the UI. So prefereably you should create your own resource bundle in your module.config, and it should be loaded automatically when needed.

  <add name="my.uniquely.named.bundle" path="ClientResources/fancy.css" resourceType="Style"/>

    <add name="my.uniquely.named.bundle" />


Feb 05, 2013 15:08
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.