Functiondojo.moduleUrl

<script src="../../js/dojo.js"></script>
defined in dojo/_base/_loader/loader.js

Returns a dojo._Url object relative to a module.

Usage

function (/*String*/ module, /*dojo._Url|String*/ url) (view source)
parametertypedescription
moduleString 
urldojo._Url|StringConstructor to create an object representing a URL. It is marked as private, since we might consider removing or simplifying it.
fieldtypedescription
.authority 
.fragment 
.host 
.password 
.path 
.port 
.query 
.scheme 
.toStringFunction 
.uri 
.user 

Examples

Example 1

var pngPath = dojo.moduleUrl("acme","images/small.png");
console.dir(pngPath); // list the object properties
// create an image and set it's source to pngPath's value:
var img = document.createElement("img");
// NOTE: we assign the string representation of the url object
img.src = pngPath.toString();
// add our image to the document
dojo.body().appendChild(img);

Example 2

you may de-reference as far as you like down the package hierarchy. This is sometimes handy to avoid lenghty relative urls or for building portable sub-packages. In this example, the acme.widget and acme.util directories may be located under different roots (see dojo.registerModulePath) but the the modules which reference them can be unaware of their relative locations on the filesystem:

// somewhere in a configuration block
dojo.registerModulePath("acme.widget", "../../acme/widget");
dojo.registerModulePath("acme.util", "../../util");

// ...

// code in a module using acme resources
var tmpltPath = dojo.moduleUrl("acme.widget","templates/template.html");
var dataPath = dojo.moduleUrl("acme.util","resources/data.json");