Comments (5)
@vince6794 - I couldn't reproduce the issue on the latest version of templ. I added an additional test in 1ca2796 to demonstrate.
Please open a new issue if you have a reproduction though.
Thanks!
from templ.
Pretty much the same problem here.
The child component cannot be called
package main
type ChildComponent struct {
}
templ (t ChildComponent) Compile() {
@layout.DefaultLayout{}.Compile(){
<div class="child-wrapper">
</div>
}
}
package main
type DefaultLayout struct {
}
templ (t DefaultLayout) head() {
<head>
<title>Test Title</title>
</head>
}
templ (t DefaultLayout) foot() {
}
templ (t DefaultLayout) Compile() {
<html>
@t.head()
<body>
<main>
{ children... }
</main>
@t.foot()
</body>
</html>
}
This example give error on the child component : layout.DefaultLayout.Render undefined (type layout.DefaultLayout has no field or method Render)
am I writing it wrong ?
from templ.
Not sure if this related discussion helps: #554
from templ.
Not sure if this related discussion helps: #554
Thanks, I experimented a bit without success much success.
The problem is mostly related to this concept: method components
I guess the line @layout.DefaultLayout{}.Compile()
fails due to the {}
parenthesis.
In fact I "hacked" it into working by assigning layout.DefaultLayout{} to a variable :
var MainLayout = DefaultLayout{}
and using it like : @layout.MainLayout.Compile(){ ... }
Maybe we need something to escale the the parenthesis in the templ file. (or at least something to declare a variable before using it in the same file)
from templ.
Interesting. The version of templ released this morning updates the child syntax parser to use the go/ast
parser, continually expanding to find the longest valid Go expression it can find. It should handle the braces well.
I'll add something like that to the tests when I'm back at my computer (replying on mobile at the moment).
from templ.
Related Issues (20)
- 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
- bug(lsp): diagnostics error on Windows due to URI encoding HOT 1
- If you write the class attribute 2 times, the second one is silently discarded HOT 1
- bug: discrepancy between buffers in `runtime.go` and `runtime/bufferpool.go` HOT 3
- `templ generate` is loading my layout into styles.css HOT 5
- documentation: templ.SafeURL is not working as described HOT 8
- Setting children from go code HOT 2
- Neovim/Template goto definition returns error: index out of range HOT 9
- proposal: render individual template fragments
- Taking too much memory with (relatively) larger files HOT 5
- Switch fallthrough not supported
- Suggestion when convert golang template to a-h/templ HOT 4
- Handle Generics for templ ('func') definition HOT 1
- Parser chokes on "<" in if statements HOT 3
- Support else ifs in conditional attributes HOT 4
- Templ removes significant white space inside <pre> tags
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.