当前位置:网站首页>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();
}边栏推荐
- 【Unity3D】GUI控件
- jsscript
- Misc (eternal night), the preliminary competition of the innovation practice competition of the National College Students' information security competition
- C language - Blue Bridge Cup - promised score
- Introduction to robotframework (I) brief introduction and use
- 全国大学生信息安全赛创新实践赛初赛---misc(永恒的夜)
- Crazy, thousands of netizens are exploding the company's salary
- Zhang Lijun: penetrating uncertainty depends on four "invariants"
- Web security SQL injection vulnerability (1)
- Linear programming matlab
猜你喜欢

codeforces每日5題(均1700)-第六天

【若依(ruoyi)】设置主题样式

Is there a completely independent localization database technology

C language - Blue Bridge Cup - promised score
![[ruoyi] set theme style](/img/e9/6a6b7113faed16c3b439230806320b.png)
[ruoyi] set theme style

淘宝焦点图布局实战

Who is the winner of PTA
![BUUCTF刷题笔记——[极客大挑战 2019]EasySQL 1](/img/37/c38a933ce7fa5d2b8fa597965ffcb2.png)
BUUCTF刷题笔记——[极客大挑战 2019]EasySQL 1

Performance analysis of user login TPS low and CPU full

StrError & PERROR use yyds dry inventory
随机推荐
My C language learning records (blue bridge) -- files and file input and output
Leetcode problem solving -- 99 Restore binary search tree
Classic interview question [gem pirate]
CSP date calculation
Technology sharing | what if Undo is too big
Pat 1046 shortest distance (20 points) simulation
Introduction to robotframework (III) Baidu search of webui automation
Self made CA certificate and SSL certificate using OpenSSL
4. File modification
Communication between microservices
MySQL advanced notes
Installation and use tutorial of cobaltstrike-4.4-k8 modified version
JS regular filtering and adding image prefixes in rich text
【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
Game theory matlab
Codeforces 5 questions par jour (1700 chacune) - jour 6
【paddle】加载模型权重后预测报错AttributeError: ‘Model‘ object has no attribute ‘_place‘
Era5 reanalysis data download strategy
银行核心业务系统性能测试方法
StrError & PERROR use yyds dry inventory