0

Since, v13 or v14, I heard that we can use "iRender" or something to inject a 2sxc module into the skin.

This was the previous way Is it possible to load a specific 2sxc module in a DNN skin?

What is the newest code for injecting a 2sxc module into a DNN theme?

2 Answers2

1

I just blogged about it today :) https://2sxc.org/en/blog/post/deep-dnn-skin-and-module-integration-towel-day-2022

Use GetScopedService() and you're good to go

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21
  • Getting error when trying to do this :( https://stackoverflow.com/questions/74886089/error-when-trying-to-inject-2sxc-app-into-dnn-template – Acer Dec 22 '22 at 08:56
  • 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:38
  • 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:38
1

The idea here is to Render the output of a 2sxc module that is already on a DNN page. You are literally inserting the rendered HTML results of the module.

So in a user control, any theme (skin or container) file, like Main.ascx, you can now (2sxc v14.01+) do this nicely with the following code. All you need to know are the page ID and module ID (below you see TabID=44 and ModuleID=122):

<%@ Import Namespace="ToSic.Sxc.Dnn" %>
<%@ Import Namespace="ToSic.Sxc.Services" %>
<%= this.GetScopedService<IRenderService>().Module(44, 122) %>

There are a lot of great use cases for this that provide the content manager with an easy to use way of editing something in the theme. Examples? Add a Featured Something in to the output of a MegaMenu? A custom list of links or social media icons in the footer without using a janky DNN all-pages module.

Note: that prior to 2sxc v14.01, the function name was .GetService<T>()

Related 2sxc Docs:

Jeremy Farrance
  • 740
  • 6
  • 11