-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
docs: specify templates should be on their own line #693
base: main
Are you sure you want to change the base?
Conversation
Thanks for taking the time to document this, I think we should supplement this with an update to the vscode syntax to avoid confusion. I also think this documentation section could benefit from the input/output style we have in other areas such as: https://templ.guide/syntax-and-usage/css-style-management#html-class-attribute Just a single input and output should be fine:
|
Me should also fix the underlying issue. It's a bit weird to not be able to do that, right? |
That's what I was thinking, I think we could document current behavior and open an issue. I think there's a bit of nuance in supporting template elements mid line.
|
Definitely has some nuances. What would the fix look like in your opinions? The LSP pushing the component to its own line? Or that templ can detect that the component exists and generate it? Only reason I didn't opt for fixing it was that I'm unsure whether the behavior would be not intuitive for someone who puts text that's just so happens to match a component function (and they want the text). |
@joerdav I'm not entirely clear on what you meant with your first comment:
are you suggesting additional pages to be modified and only having the templ input with the html output for the sections? |
Sorry for the confusion, what I meant was that if we are going to document that template elements on the same line do not work, then we should change the syntax highlighting to not highlight the element in those cases. But it sounds like we might be going for a fix instead? I think what we want is for the following to be valid, and to render
But we want to avoid breaking other peoples code who may have
|
@joerdav I've implemented what I believe to be a valid fix. There are three cases that I have used to validate it:
The only problem is now there are two failing tests. I can definitely fix them to use the new logic from point 2, but I just want to ensure that is the solution we want to proceed with? name: "templelement: bare variables are read until the end of the token",
input: `@template</div>`,
expected: TemplElementExpression{
Expression: Expression{
Value: `template`, and name: "templelement: simple, block with templelement as child",
input: `@Other(p.Test) {
@other2
}`,
expected: TemplElementExpression{
Expression: Expression{
Value: "Other(p.Test)", |
main...Waldeedle:templ:fix/parse-templ-element-expressions |
here's a visual of what I'm referring to templ Repro() {
<div>
something: @SomeComponent() // component
</div>
} case 2: templ Repro(SomeComponent templ.Component) {
<div>
something: @SomeComponent // component
</div>
} Note: currently it checks the whole template string for the case 3: templ Repro() {
<div>
something: @SomeComponent // text
</div>
} |
It wasn't explicitly written anywhere that I cannot use a template inline, the LSP is still highlighting it as a component.
Open to discuss whether or not that is accurate because I could see either way being correct. I think another appropriate solution here is to force it to go to the next line if a matching component is found but my only concern there is with name collisions