Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error generating code when nesting <a> and text in parent element. #998

Closed
zachczx opened this issue Nov 12, 2024 · 5 comments
Closed

Error generating code when nesting <a> and text in parent element. #998

zachczx opened this issue Nov 12, 2024 · 5 comments

Comments

@zachczx
Copy link

zachczx commented Nov 12, 2024

Hi, I encountered a minor bug (?) with Templ. Not a dealbreaker by any means, just made me puzzled for half an hour before realizing this was the cause when templ generate kept throwing errors.

This doesn't work - having an "a" tag immediately followed by text - throws error when generating code.

	<p>
		<a href="/" class="underline">Click here</a> if you're not redirected to the main page in 5s.
	</p>

This doesn't either.

	<p>
		<a href="/" class="underline">Click here</a><span> if you're not redirected to the main page in 5s.</span>
	</p>

This works fine.

	<p>
		<a href="/" class="underline">Click here if you're not redirected to the main page in 5s.</a>
	</p>

templ info output
templ info
(✓) os [ goos=windows goarch=amd64 ]
(✓) go [ location=C:\Program Files\Go\bin\go.exe version=go version go1.23.3 windows/amd64 ]
(✓) gopls [ location=C:\Users\z\go\bin\gopls.exe version=golang.org/x/tools/gopls v0.16.2 ]
(✓) templ [ location=C:\Users\z\go\bin\templ.exe version=v0.2.793 ]

@joerdav
Copy link
Collaborator

joerdav commented Nov 12, 2024

Hi @zachczx , thanks for the bug report. You have encountered a common footgun with templ, the issue is that the word after the a is if, here is the documentation for this behaviour: https://templ.guide/syntax-and-usage/statements#ifswitchfor-within-text

@joerdav joerdav closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2024
@zachczx
Copy link
Author

zachczx commented Nov 12, 2024

Ah I'm so sorry, I read the docs and these lines many times, but I must've had a brain fart and skipped over the "if" after.

@a-h
Copy link
Owner

a-h commented Nov 12, 2024

Did we not change the behaviour of the if parser to handle this case? I remember talking about it, maybe we overlooked making the change.

@joerdav
Copy link
Collaborator

joerdav commented Nov 12, 2024

I had the same thought @a-h ..

Maybe did we only implement it for one keyword to start with?

@joerdav
Copy link
Collaborator

joerdav commented Nov 12, 2024

#777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants