0

Within my skin I have a module container where I want to add a JavaScript file.
No problem, I use:

<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.Web.Client.ClientResourceManagement" Assembly="DotNetNuke.Web.Client" %>
<dnn:DnnJsInclude runat="server" FilePath="script.js" PathNameAlias="SkinPath" />

Only problem is, that the script is located not in the skins folder:

Portals\_default\Skins\MySkin\script.js

but in the containers folder:

Portals\_default\Containers\MySkin\script.js

Adding above code won't work as it produces a link to the skin folder:

<script src="/Portals/_default/Skins/MySkin/script.js?cdv=18" type="text/javascript"></script>

If I use this simple code, it does work:

<script src='<%= SkinPath %>script.js' />

But then I lose all advantages of the ClientResourceManagement!

Looking at the source and the documentation there are only two PathNameAlias types and none of them are for containers.

The reason why I add the script to the containers folder, is that it's only used in that one container and nowhere else.

Anyone knows a solution?
Is it easy to implement my own PathNameAlias?

jerone
  • 16,206
  • 4
  • 39
  • 57
  • Can't you just use FilePath="~/Portals/_default/Containers/MySkin/script.js" – Hans Derks Oct 16 '13 at 10:57
  • @HansDerks Does DNN automatic replace `_default` then with my current portal number? – jerone Oct 16 '13 at 11:26
  • I thought the container was installed in the _default and not in a specific portal. _default has always the same path, when you must use the current portalnumber, then I don't know. – Hans Derks Oct 16 '13 at 11:33
  • Where do new installations of a skin package go? In _default or per portal? – jerone Oct 16 '13 at 11:55
  • Depends how you install it. If you're a host, you can install it by the Extentions in Host menu and it will install in the _default. If you're just Admin then it will user the current portalnumber – Hans Derks Oct 16 '13 at 12:19
  • Ah that's interesting info. Then using hard-coded `_default` won't work. – jerone Oct 16 '13 at 12:32
  • 1
    Why not use the PortalController and get the current portal settings and use the portal id from that? – box86rowh Oct 18 '13 at 19:51

1 Answers1

0

You can use the Client Resource Manager API in your code behind to register scripts and/or stylesheets anywhere in your site directory.

In the codebehind of your module, use this

        override protected void OnInit(EventArgs e)
        {
            ClientResourceManager.RegisterScript(Parent.Page, "~/Portals/-default/Containers/MySkin/script.js");

            base.OnInit(e);
        }
rwisch45
  • 3,692
  • 2
  • 25
  • 36
  • In combination with [@box86rowh comment](http://stackoverflow.com/questions/19398831/add-javascript-file-to-container-control/20732779?noredirect=1#comment28853558_19398831) about current portal id, this mite work. – jerone Dec 24 '13 at 16:22