dotnetnuke2sxc

How do I output the DNN Page's "Large Icon" in 2sxc?


I'm making a Hero app using 2sxc. On the DNN site I'm working on, the administrator set the "Large Icon" via the page settings to have a banner image. I would like to grab this banner image and use it within the 2sxc app.

I thought I might be able to use @CmsContext.Page.LargeIcon but that renders an error:

"error CS1061: 'ToSic.Sxc.Context.ICmsPage' does not contain a definition for 'LargeIcon' and no extension method 'LargeIcon' accepting a first argument of type 'ToSic.Sxc.Context.ICmsPage' could be found"

Is it possible to grab the page's Large Icon for display within a 2sxc app?


Solution

  • We have (Accuraty has) a few utility functions that help us get at this stuff (when 2sxc doesn't make it easy in .Razor12+). In general, you can do it on the fly with something like:

    var pageTabInfo = DotNetNuke.Entities.Tabs.TabController.Instance.GetTab(PageId, SiteId);
    

    This returns a TabInfo object so then just:

    @pageTabInfo.IconFileLarge
    

    If you want a working function you can reuse:

    @inherits Custom.Hybrid.Razor14
    @using DotNetNuke.Entities.Portals // PortalSettings
    @using DotNetNuke.Entities.Tabs // TabInfo
    
    @functions {
      public TabInfo GetPage(int pageId, int siteId = -1)
      {
        if (siteId == -1)
        {
          siteId = PortalSettings.Current.PortalId;
        }
        return TabController.Instance.GetTab(pageId, siteId);
      }
    }
    

    Then call it like this:

    <p>Page (TabInfo) .IconFileLarge = @GetPage(CmsContext.Page.Id).IconFileLarge</p>
    

    Note: if you are using 2sxc v16.03 or higher, e.g.

    @inherits Custom.Hybrid.RazorTyped,

    Then instead of CmsContext.Page..., you would use MyPage...

    <p>Page (TabInfo) .IconFileLarge = @GetPage(MyPage.Id).IconFileLarge</p>