Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between liquid and cshtml page in themes views in Orchard Core

In the TheAdmin theme in OrchardCore.Themes, I see in Views folder Layout.cshtml and Layout-Login.cshtml.

In the TheAgency theme, I see Layout.liquid in views folder.

I tried to change my Layout.liquid in my views folder in my newly created theme to Layout.cshtml and when I run it, it still works.

So, what is the difference between liquid and cshtml file in themes in Orchard Core, and when should I use one over the other?

like image 200
Alexander Avatar asked Jan 26 '23 12:01

Alexander


2 Answers

They are two different view engines that you can use. Razor/cshtml is more familiar to ASP.NET developers, but its views are compiled. Liquid is a very well-known templating language in the JavaScript world, and it has the huge advantage for Orchard that its views are not compiled. That enables storing them in the database, changing them without restarting or triggering compilation, etc.

As a module author, you have a choice, and should use the one you're most comfortable with. Sometimes however, like if the view must be dynamically created for whatever reason, Liquid is the only choice.

like image 180
Bertrand Le Roy Avatar answered Feb 06 '23 16:02

Bertrand Le Roy


The reason that liquid is the only option for content editable templates is that a razor template has full access to anything you can write in C# code inside a @{ } block. This is then only limited by the execution permissions that are given to a web app. So because of this, razor templates can be a security risk to allow end users to write templates in razor.

With a liquid template you can only call liquid filters that are provided by the host that is rendering the template.

like image 41
Pete Davis Avatar answered Feb 06 '23 15:02

Pete Davis