0

I'm trying to inject a 2sxc app into a DNN template file - as per this great tutorial from WolfXMachina

Tutorial code:

<%@ Import Namespace="DotNetNuke.Entities.Modules" %>
<%@ Import Namespace="ToSic.Sxc.Dnn" %>
<%@ Import Namespace="ToSic.Sxc.Services" %>
 <%
    var moduleController = new ModuleController();
    ModuleInfo footerModule = moduleController.GetModule(39, 394);
    if (footerModule != null) {
  %>
    <%= this.GetScopedService<IRenderService>().Module(39, 394) %>
  <%
    }
  %>

I checked for the page id and grabbed the ID for the app from the 2sxc app list. enter image description here

But I'm getting the following error (Object reference not set to an instance of an object):

    DotNetNuke.Services.Exceptions.Exceptions - DotNetNuke.Services.Exceptions.PageLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at ToSic.Sxc.Dnn.DnnModuleAndBlockBuilder.GetModuleImplementation(Int32 pageId, Int32 moduleId) in C:\Projects\2sxc\2sxc\Src\Dnn\ToSic.Sxc.Dnn.Core\Dnn\DnnModuleAndBlockBuilder.cs:line 30
   at ToSic.Sxc.Blocks.ModuleAndBlockBuilder.GetBlock(Int32 pageId, Int32 moduleId) in C:\Projects\2sxc\2sxc\Src\Sxc\ToSic.Sxc\Blocks\ModuleAndBlockBuilder.cs:line 25
   at ToSic.Sxc.Blocks.RenderService.Module(Int32 pageId, Int32 moduleId) in C:\Projects\2sxc\2sxc\Src\Sxc\ToSic.Sxc\Blocks\Renderers\RenderService.cs:line 124
   at ToSic.Sxc.Dnn.Services.DnnRenderService.Module(Int32 pageId, Int32 moduleId) in C:\Projects\2sxc\2sxc\Src\Dnn\ToSic.Sxc.Dnn.Core\Dnn\Services\DnnRenderService.cs:line 37

What I'm I doing wrong or is there another location where I can get the app ID?

Acer
  • 75
  • 1
  • 11

1 Answers1

0

I'm a bit confused about you mentioning the AppId. It also doesn't appear in your code above, and you don't need it.

Basically you would add a module to any page - usually hidden.

Then you would use the ID of that page and module for this.

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21
  • I was under the impression that it had to be the appid, like the specific one I'm using on that hidden page. Ok, so if I have a 2sxc app or 2sxc content module that I want to show on the template, I basically just need the page id and find the module id from the extension list? And there was nothing wrong with my implementation code as per the error? Just use the module id and not appid? Sorry, new to DNN and 2sxc here, but I'm seeing the potential... – Acer Dec 24 '22 at 11:54
  • Battling to find out how to get the module ID. If you're following this, please advise. Thanks! – Acer Jan 09 '23 at 10:49
  • Ok so I managed to find how to get the Module ID (Dev tools -> Inspect front-end output of the module. ID is listed there.) However, it seems that there is some sort of error with the if statement in this code (to check for the module first). If I remove the if statement and just display output the module, then it works. With the if, nothing is displayed. – Acer Jan 09 '23 at 13:39
  • This code seems to do nadda / nothing: <% var moduleController = new ModuleController(); ModuleInfo footerModule = moduleController.GetModule(39, 394); if (footerModule != null) { %> <%= this.GetScopedService().Module(39, 394) %> <% } %> – Acer Jan 09 '23 at 13:40