DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Razor in a skin file

Sort:
You are not authorized to post a reply.





New Around Here





    Hi,

    I have a razor file that contains code that I'd like to include in several skin files but I'm having a hard time figuring out how to include it. 

    I tried render page as such

    <section>
        <div id="ContentPane" runat="server"></div>
    </section>

    @RenderPage("_GetArticles.cshtml")
     

    But this gives a 500 server error. 

    I've also tried this:

    <section>
        <!-- FEATURED CONTENT START -->
        <div id="ContentPane" runat="server"></div>
        <!-- FEATURED CONTENT END -->
    </section>

    <% @RenderPage("_GetArticles.cshtml") %>

    It does the same. What is the proper syntax for this?
     






    Veteran Member





      Well, the Skin is Webforms based so you cannot include Razor by default AFAIK.
      There are options to use Razor in a DNN Extensions though.

      1. I think you could create a Razor skin object, but I never tried and I'm not sure.
      2. You can create or use a module that supports Razor and add that to the page.
        Examples: Razor host, Open Content, 2SXC
      3. Open Content has a Skin object that allows you to insert Razor code.

       






      New Around Here





        Thanks Tim,

        That's a bummer. We are using the RazorHost module and RenderPage works in there, was just hoping to be able to do the same in a skin. That way the code can be placed in one skin file instead of numerous Razor ones. It's a maintenance thing.

        We're trying to stay away from 3rd party modules as much as possible and stick to the core. With the exception of your stylehelper skin object of course. That's been very helpful and we've had no issues with it.

        Thankfully with the core's Razorhost module we can create forms so no need for form builder modules anymore. It's been a real gamechanger for us. We really don't need too many third party mods now with that in the arsenal.





        Senior Member





          There are a number of ways to include/use Razor.  It just depends on the module(s) you're using/building, but Timo is right.  For the foreseeable future, the theme engine is and will be based on webforms.  Luckily, nearly anything you'd want to do using Razor is still available.  You'd just be using a slightly different syntax, for now.  






          Veteran Member





            Posted By Faith Coder on 11/16/2023 6:35 PM
            Thanks Tim,

            That's a bummer. We are using the RazorHost module and RenderPage works in there, was just hoping to be able to do the same in a skin. That way the code can be placed in one skin file instead of numerous Razor ones. It's a maintenance thing.

            We're trying to stay away from 3rd party modules as much as possible and stick to the core. With the exception of your stylehelper skin object of course. That's been very helpful and we've had no issues with it.

            Thankfully with the core's Razorhost module we can create forms so no need for form builder modules anymore. It's been a real gamechanger for us. We really don't need too many third party mods now with that in the arsenal.

            As Will said you can include C# in a Theme, and the code should not be much different.
            For those landing on this page wondering how the Open Content Skin Object works, here's an example: https://github.com/40fing...10.00-OC-Skin-Object

             

             

             

            You are not authorized to post a reply.

            These Forums are dedicated to the discussion of DNN Platform.

            For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

            1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
            2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
            3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
            4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
            5. No Flaming or Trolling.
            6. No Profanity, Racism, or Prejudice.
            7. Site Moderators have the final word on approving / removing a thread or post or comment.
            8. English language posting only, please.

            Would you like to help us?

            Awesome! Simply post in the forums using the link below and we'll get you started.

            Get Involved