Comments (6)
The mission of templ is to:
Enable Go developers to build strongly typed, component-based HTML user interfaces with first-class developer tooling, and a short learning curve.
So, rendering text isn't part of the plan, but I've suggested how you can use templ to do something similar at #385 (comment)
from templ.
Thanks for the proposal, I wonder what value add this has over something like:
func SimpleEmail(to string) {
return fmt.Sprintf(`
Hello %s,
Welcome to our system.
Thanks,
Some Team
`, to)
}
Would you suggest for control flow statements such as for
, switch
, if
to be valid? As this may be hard to parse in this context.
from templ.
Yes, conditions , loops and expressions would be powerful. We can extent this latter even to support markdown.
from templ.
It may be powerful, but we need to think about how it would be even possible.
The way templ parses Go code is as follows...
It looks for a keyword at the start of a node such as for
.
Then it parses the go expression up to the opening curly brace (this can be multiple lines of go code) {
.
And then we continue parsing nodes until the closing curly brace }
.
If it finds a keyword but then a subsequent step of parsing the statement fails, we don't assume anything, and throw an error.
By "we don't assume anything", what I mean is that if the stuff after the word for
isn't valid go code, we don't fallback to it being regular text, (to avoid leaking code accidentally).
This is why in cases such as <div>for example</div>
, you will see an error.
We basically say "hey, we're a bit confused here, you might have been trying to write a for loop, can you help?".
Then the dev can either fix the for loop syntax or show that they were trying to write normal text by doing <div>{
for example}</div>
In the context of pure text, I'm struggling to see how we would parse it without encountering lots of errors like this.
from templ.
Yes, I understand. I will also think. Maybe also discuss it with other collaborators.
Thanks for considering it.
from templ.
This seems far to error-prone for the parser and JSX also does not allow it, for comparison. What you can do in JSX is either quoted the string "foo"
or unquoted inside fragements, e.g. <Fragment>foo</Fragment>
or shorthand <>foo</>
, both which should be much easier to parse.
from templ.
Related Issues (20)
- Templ formatting breaks imports at v0.2.747 HOT 7
- Composable templates do not render properly in tests HOT 1
- App freeze using air proxy HOT 1
- templ-vscode "Request textDocument/codeAction failed" HOT 2
- Streaming Not Working
- [Proposal] Improve embedding components HOT 2
- proposal: Go comments within HTML tags HOT 1
- Raw go errors if block ends with a comment
- LSP crashes after being started by kakoune-lsp HOT 4
- How to prevent cache HOT 1
- .templ file with only script elements leads to unused import HOT 1
- Anyway to instantiate a templ once per rendering context? HOT 4
- performance: templ parse takes a long time and uses high CPU when unclosed void elements are used HOT 8
- Little typo in streaming documentation
- bug: `templ generate --watch --proxy` triggers 2 browser reload events HOT 1
- bug: ambiguous child/string expression grammar HOT 4
- bug: go to definition causes error in Neovim v0.10.x HOT 11
- LSP - gopls command error HOT 3
- bug: ComponentScript rendered even when 'if condition' fails HOT 1
- GoToDef .Templ templ() instead of .go func () HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from templ.