How to create a DNN widget?

Viewed 26

If I understood correctly, DNN widget is a way to add a js to every page on the website using module or theme. Right?

My goal evantually is to add a js to every page on a portal and preferably to do that via module that has no need to be added to every page manually. My plan B is adding module and using setting "Display Module on All Pages", but widget seems to be a better way to do that.

At first I've tried to use this instruction. I've added the YourCompany.Widgets.SampleWidget.js file to root of existing DNN module. Also in the .dnn manifest file inside components tag I've added another component like this:

<component type="Widget">
  <widgetFiles>
    <basePath>YourCompany</basePath>
    <widgetFile>
      <name>YourCompany.Widgets.SampleWidget.js</name>
    </widgetFile>
    <widgetFile>
      <name>license.txt</name>
    </widgetFile>  
    <widgetFile>
      <name>releasenotes.txt</name>
    </widgetFile>
  </widgetFiles>
</component>

I've got this error on module installation:

Failure File specified in the dnn could not be found in the zip file: - D:\Projects\website.com.ua\Host\Install\Temp\vp1vioj1\YourCompany.Widgets.SampleWidget.js

vp1vioj1 part is changing every time (seems like it's some unique id that is generating on module install).

Then I tried to place this widget component inside another package tag after checking this article. Like this:

<dotnetnuke type="Package" version="5.0">
  <packages>
    <package name="ModuleName" type="Module" version="00.00.01">
      <!-- some module content here -->
    </package>

    <package name="YourCompany.SampleWidget" type="Widget" version="00.00.01">
      <components>
        <component type="Widget">
          <widgetFiles>
            <basePath>YourCompany</basePath>
            <widgetFile>
              <name>YourCompany.Widgets.SampleWidget.js</name>
            </widgetFile>
          </widgetFiles>
        </component>
      </components>
    </package>
  </packages>
</dotnetnuke>

But I still got the same error on install. I didn't find any other instructions or documentations regarding widgets. When I tried to check the DNN source code - it seems to be also very time consuming and hard way. So could you please help me to clarify this?

2 Answers

Support for Widgets in DNN Platformnwas dropped a number of years ago.

Your best option if you want something ok all pages would either be to look at a SkinObject, like the breadcrumb or Login for example. Or a traditional module but marking it “display on all pages”

First, you might want to take a look at the concept of DNN Extensions and how they are built and packaged.

If examples of versions DNN extensions, https://github.com/WillStrohl/dnnextensions. The examples include a widget. So check it out.

Now, what you posted looks like a .dnn file, which the the manifest file that is intended to be a part of a packaged DNN extension. Code and other bits and pieces go into the packaged extension (really a specially named zip file). The packaged extension is installed into your DNN installation via the Extensions Persona Bar page (click the Install Extension there).

From my experience with DNN (2006 to now), I believe that I can say that a DNN Widget is something that I've never had anything to do with. So, you may be barking up an old any dying tree in the project.

If you want something included on every page, it makes more sense to include it in the theme (skin). If you want a javascript file, add that to your theme project and have the .ascx files include it, probably using https://docs.dnncommunity.org/api/DotNetNuke.Web.Client.ClientResourceManagement.html (see https://docs.dnncommunity.org/api/DotNetNuke.Web.Client.ClientResourceManagement.html)

But, if you are determined to use a widget, start with https://www.kalyani.com/blog/2009/12/25/dotnetnuke-widgets-guide-part-1-of-4/

Related