当前位置:网站首页>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();
}边栏推荐
- 【paddle】加载模型权重后预测报错AttributeError: ‘Model‘ object has no attribute ‘_place‘
- CSP numeric sort
- Polymorphic day02
- Handwriting database client
- Derivation of anti Park transform and anti Clarke transform formulas for motor control
- Selenium share
- My C language learning records (blue bridge) -- files and file input and output
- Is there a completely independent localization database technology
- Mysql database operation
- SD card reports an error "error -110 whilst initializing SD card
猜你喜欢

【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用

js 正则过滤和增加富文本中图片前缀

My C language learning record (blue bridge) -- on the pointer
![[unity3d] GUI control](/img/ef/9de2aa75c67cf825983867a913db74.png)
[unity3d] GUI control

MySQL advanced notes

IPv6 jobs
![[Chongqing Guangdong education] higher mathematics I reference materials of Southwest Petroleum University](/img/0f/520242492524522c887b6576463566.jpg)
[Chongqing Guangdong education] higher mathematics I reference materials of Southwest Petroleum University

Mysql database operation
![[concept] Web basic concept cognition](/img/27/14bcd73ca70d136436a4382a1b4bd1.jpg)
[concept] Web basic concept cognition

Introduction to robotframework (II) app startup of appui automation
随机推荐
CobaltStrike-4.4-K8修改版安装使用教程
Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
Audio audiorecord binder communication mechanism
Leetcode problem solving -- 108 Convert an ordered array into a binary search tree
Buuctf question brushing notes - [geek challenge 2019] easysql 1
Erreur de la carte SD "erreur - 110 whilst initialisation de la carte SD
适合程序员学习的国外网站推荐
手写数据库客户端
深入探究指针及指针类型
这些不太会
OCR文字识别方法综述
如何做好功能测试
[network security interview question] - how to penetrate the test file directory through
Modeling specifications: naming conventions
jsscript
2022工作中遇到的问题四
2.13 simulation summary
继承day01
CSP date calculation
有没有完全自主的国产化数据库技术