6

Rust与Go两种html模板引擎Tera、templ

 6 months ago
source link: https://www.jdon.com/72637.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Rust与Go两种html模板引擎Tera、templ

有人说:为什么要使用PHP?

  • PHP有一个比其他语言更好的模板系统,当然除了Go语言
  • PHP有一个比go更好的模板系统,因为最初的php本身就是一种模板语言。
  • 广泛应用:HTMXJSX
  • 在jvm上,你基本上拥有你能想到的所有模板语言。你觉得这个怎么样? https://jte.gg
  • Svelte的模板太好了,接近HTML,并且与JavaScript互操作

1、tera:基于 Jinja2/Django 的 Rust 模板引擎
Tera 是一个受Jinja2和Django 模板语言启发的模板引擎。本项目证明Rust上也有一个很酷的模板系统

<title>{% block title %}{% endblock title %}</title>
<ul>
{% for user in users %}
  <li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>

2、Go模板:https://templ.guide/
创建渲染 HTML 片段的组件,并将它们组合起来以创建屏幕、页面、文档或应用程序。

  • 服务器端渲染:部署为无服务器函数、Docker 容器或标准 Go 程序。
  • 静态渲染:创建静态 HTML 文件以根据您的选择进行部署。
  • 编译代码:组件被编译成高性能的 Go 代码。
  • 使用 Go:调用任何 Go 代码,并使用标准if、switch、 和for语句。
  • 无 JavaScript:不需要任何客户端或服务器端 JavaScript。
  • 出色的开发人员体验:附带 IDE 自动完成功能。
package main

templ Hello(name string) {
  <div>Hello, { name }</div>
}

templ Greeting(person Person) {
  <div class="greeting">
    @Hello(person.Name)
  </div>
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK