OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.43k stars 2.4k forks source link

[Teamplates][Razor] Support Razor based templates via `RazorLight` #11048

Closed xperiandri closed 2 years ago

xperiandri commented 2 years ago

Is your feature request related to a problem? Please describe.

It would be very nice to be able to write markup inside the admin panel not only using Liquid but also Razor

Describe the solution you'd like

Add ability to write templates using Razor by including https://github.com/toddams/RazorLight and adding a switch in the template to switch the template language

Describe alternatives you've considered

Do not use Templates but hard code pages via compiled Razor

hishamco commented 2 years ago

It's a good idea to provide an option to either add Liquid or Razor templates from within the admin. May be it's by design while the Razor need compilation. @sebastienros is there a reason that we don't provide such option?

jtkech commented 2 years ago

Security issue as everything can be done through razor

Skrypt commented 2 years ago

That's RazorLight so I'm assuming that it removes access to "@using" a lot of security sensible assemblies? Need to understand what RazorLight is about if not.

sebastienros commented 2 years ago

typeof(Type).GetType("EvilType").GetMethod("EvilMethod").Invoke()

Skrypt commented 2 years ago

Reflection is evil 😄

ns8482e commented 2 years ago

@sebastienros can build oczor for razor syntax 😊

ns8482e commented 2 years ago

@xperiandri I’d say if you prefer to use razor syntax then use it during build time for modules and themes

And use liquid for light weight rendering for non authoring user

hishamco commented 2 years ago

Lol, I'm not with using RazorLight ;) provide an elegent way to create Razor templates like Liquid

deanmarcussen commented 2 years ago

What @sebastienros is trying to say is that liquid is a safe language to edit in a cms because it’s designed to be safe.

razor or razor light is not (I’ve used it, it’s good but unsafe), so you could have users doing all sorts of things, like method invokes, or stackoverflows from infinite recursion, which can bring the site to a grinding halt

hishamco commented 2 years ago

Agree, but could be useful during development

sebastienros commented 2 years ago

@ns8482e well, would not be very hard to build something like razor that is as safe as liquid and uses most of C# syntax. There would be limits for sure, but the overall experience could be here, meaning @ and c# syntax.

hishamco commented 2 years ago

Agree, but could be useful during development

ns8482e commented 2 years ago

@hishamco for development I feel watch and hot reload works well, but slow than liquid

hishamco commented 2 years ago

Right, but for C# developer creating .cshtml templates may easier for them because they already use ASP.NET Core & Razor. It's matter of choice

Skrypt commented 2 years ago

Liquid is super fast, I don't know where is the issue. Learning Liquid? You can always use a custom module and build your own Razor precompiled templates. And I think we agreed on, a while back, to not reintroduce runtime compilation in OC.

hishamco commented 2 years ago

The problem is not with Liquid, but why we didn't offer Razor templates while we already can create layouts and views in modules using Razor

Skrypt commented 2 years ago

Because from RUNTIME it's not safe to allow to use System.IO for example. And Razor doesn't prevent anyone from doing this, which leads to security issues.

hishamco commented 2 years ago

I think that means we enforce everyone to use Liquid to do templating