How to inject 2sxc apps into a DNN theme and why you would want to do that
Posted in DNN, How To, Video on June 8, 2022
I first used this feature because I wanted to build a mega-menu on a DNN website that the customer could edit easily themselves but I didn't want the overhead of having to manage the app on every page it gets added to.
If you're wanting to both provide the best content editor experience you can for your customers, but also make your life as a developer easier, then check out this 6 minute video:
If you just want the solution and the code, here it is:
- Create an app on a hidden page (not visible by users)
- Take note of the Page ID and Module ID
- Include the code below into your theme. The first two lines are register tags that you only need once. The third line is the actual line that gets the module so you put that wherever you want the module to exist.
<%@ Import Namespace="DotNetNuke.Entities.Modules" %>
<%@ Import Namespace="ToSic.Sxc.Dnn" %>
<%@ Import Namespace="ToSic.Sxc.Services" %>
<%= this.GetScopedService<IRenderService>().Module(39, 394) %>
The first number ("39") is your page ID. You can find that under Page Settings. The second number ("394") is the module ID. You can find your module ID by inspecting the page source.
Big shoutout to Daniel Mettler for this feature but also Jeremy Farrance of Accuraty for chatting with me about the new implementation!
It's that easy! I hope you find ways to integrate this into your websites. If you ever need help with stuff like this, please reach out to me at firstname.lastname@example.org
Founder & Lead Developer at Wolf X Machina