Giter Site home page Giter Site logo

Comments (5)

a-h avatar a-h commented on September 28, 2024 1

@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.

guilty-p01nt3r avatar guilty-p01nt3r commented on September 28, 2024

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.

a-h avatar a-h commented on September 28, 2024

Not sure if this related discussion helps: #554

from templ.

guilty-p01nt3r avatar guilty-p01nt3r commented on September 28, 2024

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.

a-h avatar a-h commented on September 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.