سؤال

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?

هل كانت مفيدة؟

المحلول

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);
        }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top