Difference between liquid and cshtml page in themes views in Orchard Core
Asked Answered
G

2

6

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?

Gielgud answered 31/3, 2019 at 0:49 Comment(0)
R
10

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.

Roentgenogram answered 28/4, 2019 at 17:54 Comment(2)
Is there a way to get code-completion or intellisense in Visual Studio for Liquid templates? I see there's an extension for VS Code but can't find one for VS.Docilu
Yes, it looks like only VS Code extensions are available on the marketplace.Roentgenogram
J
3

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.

Jezabella answered 3/5, 2019 at 7:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.