Search code examples
dotnetnuke2sxc

How do I render a 2sxc module into a DNN theme?


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?


Solution

  • 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: