当前位置:网站首页>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();
}边栏推荐
- Briefly describe the implementation principle of redis cluster
- Performance test method of bank core business system
- 原型图设计
- How to do function test well
- [ruoyi] ztree custom icon (iconskin attribute)
- 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
- Self made CA certificate and SSL certificate using OpenSSL
- IPv6 jobs
- 八道超经典指针面试题(三千字详解)
猜你喜欢

Taobao focus map layout practice

Fault analysis | analysis of an example of MySQL running out of host memory

Introduction to robotframework (II) app startup of appui automation
![[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
![[kubernetes series] learn the exposed application of kubernetes service security](/img/61/4564230feeb988886fe595e3125ef4.png)
[kubernetes series] learn the exposed application of kubernetes service security

Analyze menu analysis

Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?

OCR文字识别方法综述
![Buuctf question brushing notes - [geek challenge 2019] easysql 1](/img/37/c38a933ce7fa5d2b8fa597965ffcb2.png)
Buuctf question brushing notes - [geek challenge 2019] easysql 1

Linear regression and logistic regression
随机推荐
Leetcode problem solving -- 173 Binary search tree iterator
Crazy, thousands of netizens are exploding the company's salary
Introduction to robotframework (I) brief introduction and use
[concept] Web basic concept cognition
Daily question brushing plan-2-13 fingertip life
Differences and application scenarios between resulttype and resultmap
Eight super classic pointer interview questions (3000 words in detail)
SD卡報錯“error -110 whilst initialising SD card
原型图设计
微服务注册与发现
【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service
Analyze menu analysis
Era5 reanalysis data download strategy
不赚钱的科大讯飞,投资价值该怎么看?
Some problem records of AGP gradle
华为、H3C、思科命令对比,思维导图形式从基础、交换、路由三大方向介绍【转自微信公众号网络技术联盟站】
MySQL advanced notes
Selenium share
CSP numeric sort
[unity3d] GUI control