TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Templ: A language for writing HTML user interfaces in Go

228 点作者 nalgeon超过 1 年前

26 条评论

ralmidani超过 1 年前
There is a very intense backlash against technology like React, due to the unbelievable complexity that has crept into building “modern” JS apps.<p>This backlash is quite understandable. I believe Ember&#x2F;React&#x2F;Vue&#x2F;Angular&#x2F;etc. were all created with good intentions, but with the ecosystems of bolted-on technologies and now-necessary build tools, they have all become unmanageable monstrosities.<p>So people want to go “back to basics”. Personally, while I loved Ember with CoffeeScript (talking to a Django server via JSON) in 2015-2017, I can’t even revive the app I built without a massive effort to upgrade and ditch all the deprecated, unsupported dependencies (which might take more time than modifying my actual app code).<p>So I’m just going to rewrite the Web client with htmx (with Django rendering the actual templates). No churn and dependency hell, no build tools, no nonsense. Just a single script tag and some HTML attributes. For special cases that can’t be covered by htmx, there’s hyperscript (just add another script tag). Since browsers intend to maintain backward compatibility indefinitely, forced upgrades should be minimal to non-existent.<p>It’s a shame JS ended up being perceived as a villain, because it was meant to enable rich client applications within browsers, which are the most universally-compatible and commodified client you can possibly run such apps in.
评论 #38604854 未加载
twelfthnight超过 1 年前
Recently I&#x27;ve been drifting away from template engines toward native data structures + serialization for programmatically creating html&#x2F;yaml. For example, CDK is following this pattern for building cloud configuration YAML.<p>Do folks know of standard libraries or patterns in Go or Rust to generate HTML without string templating? (As mentioned elsewhere, I&#x27;m looking for a backend for HTMX)
评论 #38598328 未加载
评论 #38598322 未加载
评论 #38598407 未加载
评论 #38598809 未加载
评论 #38601332 未加载
评论 #38598531 未加载
评论 #38598298 未加载
donatj超过 1 年前
I was initially skeptical, because I feel like the built-in HTML templating is really powerful and good. Recently however, I listened to an episode of the &quot;Go Time&quot; podcast[1] featuring the author and he made some very compelling cases for it.<p>The most compelling to me is that Templ templates are compile time safe, rather than crashing at run time like the built-in templates.<p>1. <a href="https:&#x2F;&#x2F;changelog.com&#x2F;gotime&#x2F;291" rel="nofollow noreferrer">https:&#x2F;&#x2F;changelog.com&#x2F;gotime&#x2F;291</a>
e67f70028a46fba超过 1 年前
Seeing a lot of people use this as part of the GoTH stack: go, temple &amp; htmx
评论 #38600261 未加载
评论 #38598408 未加载
评论 #38599181 未加载
lihaoyi超过 1 年前
Part of a long line of similar projects: XHP, Pyxl, JSX. My own project Scalatags is pretty popular in the Scala community.<p>The approach works surprisingly well, both server side and running in the browser (JSX, or Scalatags+Scala.js). There are plenty of websites that don&#x27;t need heavy client-side interactivity where server side templating + a sprinkling of client side logic works just fine. This is especially true if you can share code between client and server (e.g. via JSX&#x2F;React or Scalatags&#x2F;Scala.js)<p>You get typechecking, interop with normal code, and a high performance runtime for free. That&#x27;s a lot to like!
评论 #38598671 未加载
TobyTheDog123超过 1 年前
While this is incredible and I can&#x27;t wait to use this with HTMX, I really wish it didn&#x27;t require a CLI to generate the *_templ.go files.<p>Code generation is something I saw in Flutter&#x2F;Dart a lot and it entirely killed my interest in it (mostly with JSON serialization&#x2F;deserialization to classes).<p>Thankfully, it&#x27;s by no means a show-stopper for me thanks to their hot reloading functionality. <a href="https:&#x2F;&#x2F;templ.guide&#x2F;commands-and-tools&#x2F;hot-reload" rel="nofollow noreferrer">https:&#x2F;&#x2F;templ.guide&#x2F;commands-and-tools&#x2F;hot-reload</a>
评论 #38694194 未加载
评论 #38603149 未加载
diceduckmonk超过 1 年前
How does this compare to html&#x2F;template in the Go standard library?<p><a href="https:&#x2F;&#x2F;pkg.go.dev&#x2F;html&#x2F;template" rel="nofollow noreferrer">https:&#x2F;&#x2F;pkg.go.dev&#x2F;html&#x2F;template</a><p>Which is based on top of text&#x2F;template.
评论 #38598578 未加载
评论 #38598787 未加载
justech超过 1 年前
The standard templating in Go has been good enough for my small projects, and I usually avoid adding libraries if I can help it. But seeing this makes me want to try it just to see how it compares.
评论 #38600715 未加载
评论 #38598705 未加载
jimmyed超过 1 年前
Nice! I like how it can double as a static site generator, so you can replace Hugo&#x2F;Jekyll with this. That might need some glue code&#x2F;extensions to the language though.
评论 #38604011 未加载
评论 #38599193 未加载
tbarbugli超过 1 年前
This is pretty useful <a href="https:&#x2F;&#x2F;www.jetbrains.com&#x2F;help&#x2F;go&#x2F;integration-with-go-templates.html#define-mapping-of-a-type-between-go-template-and-application" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.jetbrains.com&#x2F;help&#x2F;go&#x2F;integration-with-go-templa...</a> to improve productivity when working with templates in Go
mjlee超过 1 年前
There&#x27;s an episode of the podcast Go Time hosting &quot;Adrian Hesketh, the creator of Templ, and Joe Davidson, one of the maintainers on the project.&quot;<p><a href="https:&#x2F;&#x2F;changelog.com&#x2F;gotime&#x2F;291" rel="nofollow noreferrer">https:&#x2F;&#x2F;changelog.com&#x2F;gotime&#x2F;291</a>
ducktective超过 1 年前
So I guess SSR is back on the menu? I wonder what the workflow is like.<p>If one wants to go Go+HTMX route, how does one write a webapp with handling auth and sessions and everything? I assume the backend is not <i>just</i> an API?<p>It&#x27;d be nice if one points to an example repo developed with this method.
评论 #38599177 未加载
评论 #38600837 未加载
评论 #38602337 未加载
chabad360超过 1 年前
From my brief usage it seems to lack a couple of basic stuff, but nothing that couldn&#x27;t be added later on.<p>But, I am curious why they decided to go with reserving keywords (like if and for) instead of doing what JSX does and just wrapping any Go code in braces.
zwnow超过 1 年前
To be honest, I tried working with it and it was really confusing. I&#x27;d just rather keep writing out the HTML I want to return and keep my applications simple and straightforward.
20after4超过 1 年前
Isn&#x27;t this basically PHP, but in go? Or am I missing something?
评论 #38598091 未加载
评论 #38599791 未加载
评论 #38598065 未加载
rickette超过 1 年前
&quot;A HTML templating language for Go that has great developer tooling&quot; as long as you&#x27;re using VSCode... I don&#x27;t see a JetBrains (GoLand&#x2F;IntelliJ) plugin.
评论 #38599657 未加载
AsthmaBoy超过 1 年前
Here is an example of an old technology<p>TAL -Template Attribute Language<p><a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Template_Attribute_Language" rel="nofollow noreferrer">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Template_Attribute_Language</a><p>which happens to have an (also old) implementation i Go <a href="https:&#x2F;&#x2F;github.com&#x2F;owlfish&#x2F;tal">https:&#x2F;&#x2F;github.com&#x2F;owlfish&#x2F;tal</a><p>I wonder what opinion HN has on this type of templating language?
shp0ngle超过 1 年前
That&#x27;s nice. I&#x27;m a heavy user of go html templating and it gets tiring after a while - it has no type checking, methods and attributes are called the same way, calling Parse is awkward, adding Sprig is pretty much required, the order you call functions is lisp-like, it&#x27;s all weird.<p>This seems to be much nicer.
EdwardDiego超过 1 年前
Codegen based?<p>Edit: Yep, codegen based.
everybodyknows超过 1 年前
Emacs support for syntax highlighting of .templ files would be helpful.<p><a href="https:&#x2F;&#x2F;templ.guide&#x2F;commands-and-tools&#x2F;ide-support" rel="nofollow noreferrer">https:&#x2F;&#x2F;templ.guide&#x2F;commands-and-tools&#x2F;ide-support</a>
qaq超过 1 年前
Great project. Part of my go to stack now (FE:Templ+Htmx BE: Go,sqlc, postgres)
KingOfCoders超过 1 年前
Currently switching from Echo&#x2F;Jet to Echo&#x2F;Templ - compilation (generation) is a little bit annoying but writing simpler Go code in templates makes a difference, also easier to compose.
pier25超过 1 年前
This is great.<p>Is there a way to do code colocation with templates? I mean for writing presentation logic alongside the html.<p>Asking because it seems templ functions only allow html.
al_be_back超过 1 年前
useful for generating tedious HTML emails e.g. export Thread to Email.
peefy超过 1 年前
A great project!
obilgic超过 1 年前
Would have been amazing 10 years ago. Client side js is what would make this messy to use in big projects imho.
评论 #38597979 未加载
评论 #38597884 未加载
评论 #38599309 未加载
评论 #38597909 未加载