当前位置:网站首页>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();
}
边栏推荐
- 继承day01
- tcpdump: no suitable device found
- 银行核心业务系统性能测试方法
- My C language learning records (blue bridge) -- files and file input and output
- Day 50 - install vsftpd on ceontos6.8
- 2.11 simulation summary
- Leetcode problem solving -- 108 Convert an ordered array into a binary search tree
- Distributed service framework dobbo
- What are the principles of software design (OCP)
- My C language learning record (blue bridge) -- on the pointer
猜你喜欢
Performance analysis of user login TPS low and CPU full
MySQL advanced notes
I sorted out a classic interview question for my job hopping friends
Taobao focus map layout practice
MySQL advanced notes
Solution: attributeerror: 'STR' object has no attribute 'decode‘
2022工作中遇到的问题四
[matlab] access of variables and files
How to do function test well
Microservice registration and discovery
随机推荐
Taobao focus map layout practice
[ruoyi] ztree custom icon (iconskin attribute)
ERA5再分析资料下载攻略
BUUCTF刷题笔记——[极客大挑战 2019]EasySQL 1
IPv6 jobs
SD卡報錯“error -110 whilst initialising SD card
Distributed service framework dobbo
Analyze menu analysis
Day 50 - install vsftpd on ceontos6.8
淘宝焦点图布局实战
tcpdump: no suitable device found
Buuctf question brushing notes - [geek challenge 2019] easysql 1
真机无法访问虚拟机的靶场,真机无法ping通虚拟机
【指针训练——八道题】
Redis cache breakdown, cache penetration, cache avalanche
What is the investment value of iFLYTEK, which does not make money?
Eight super classic pointer interview questions (3000 words in detail)
技术分享 | undo 太大了怎么办
Some problem records of AGP gradle
继承day01