当前位置:网站首页>An article about liquid template engine
An article about liquid template engine
2022-07-06 03:11:00 【Up technical control】
background
Usually, for example, to develop a code generator, you usually set a template , Then there are many variables , Generate files based on data . At this time, the template engine comes in handy .
Let's introduce Liquid. What is? Liquid Well , It's like java、c# Like programming languages ,Liquid It is also an independent language , It doesn't make a big difference , The basic functions are . Dynamically generate files , You can output variables , Operation array, etc , These can achieve .
Official introduction
Liquid Is an open source template language , from Shopify Create and use Ruby Realization . It is Shopify The bones of the theme , And it is used to load the dynamic content of the store system .
Liquid grammar
Liquid The code can be divided into object (object)、 Mark (tag) and filter (filter).
object
object tell Liquid Where on the page is the content displayed . Object and variable names are identified by double curly braces :{ { and }}.
Mark (tag)
Mark (tag) Created the logic and control flow of the template . They are identified by a single bracket plus a percent sign :{% and %}.
filter
filter change Liquid Object output . They are used for output , Through one | symbols .
The original address :
https://github.com/Shopify/liquid
c# special Dot Liquid
Then based on c# Is there a corresponding one liquid Plugins , There are .Dot Liquid.
DotLiquid Compared with Mvc Default template engine Razor The benefits of a :
Because there is no need to compile to the assembly and then load
The first rendering is fast
No memory leaks
Usage method
1、nuget install using DotLiquid;
2、 Define the entity , Inherit : Drop Is the key
public class DotLiquidMdDrop : Drop
{
private readonly Questions questions;
public List<Answer> answer
{
get { return questions.Answer; }
}
public DotLiquidMdDrop(Questions questionsPara)
{
questions = questionsPara;
}
}3、 Here we make some test data , And call
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DotLiquidDemo1(string template)
{
string test = GetInterIDList(template);
ViewData["template"] = Template.Parse(test).Render(Hash.FromAnonymousObject(
new
{
questions = new List<DotLiquidMdDrop>() {
Getmork()
, Getmork()
, Getmork()
// , new DotLiquidMdDrop(new Questions() { Answer =new List<Answer> () { new Answer() { option = "Aa", optiontext = " Options content 1111" }, new Answer() { option = "Aa", optiontext = " Options content 1111" } } })
}
}));
return View();
}边栏推荐
- Is there a completely independent localization database technology
- SD卡报错“error -110 whilst initialising SD card
- The difference between sizeof and strlen in C language
- Reverse repackaging of wechat applet
- . Net 6 and Net core learning notes: Important issues of net core
- I sorted out a classic interview question for my job hopping friends
- 【若依(ruoyi)】启用迷你导航栏
- Installation and use tutorial of cobaltstrike-4.4-k8 modified version
- 微服务间通信
- BUUCTF刷题笔记——[极客大挑战 2019]EasySQL 1
猜你喜欢
随机推荐
What are the principles of software design (OCP)
Briefly describe the implementation principle of redis cluster
八道超经典指针面试题(三千字详解)
Analyze menu analysis
Solution: attributeerror: 'STR' object has no attribute 'decode‘
Some problem records of AGP gradle
Maturity of master data management (MDM)
【指针训练——八道题】
Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?
I sorted out a classic interview question for my job hopping friends
Communication between microservices
Selenium share
淘宝焦点图布局实战
Atcoder beginer contest 233 (a~d) solution
JS regular filtering and adding image prefixes in rich text
有没有完全自主的国产化数据库技术
原型图设计
Fault analysis | analysis of an example of MySQL running out of host memory
What is the investment value of iFLYTEK, which does not make money?
Game theory matlab
![[pointer training - eight questions]](/img/fd/1aa3937548a04078c4d7e08198c3a8.png)




![[matlab] access of variables and files](/img/cf/6f3cfdc4310fcf0bdcaa776d68261e.jpg)

![[ruoyi] enable Mini navigation bar](/img/28/a8b38aecd90c8ddc98333f0e2d3eab.png)