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

SUGGESTION: Handle plan HTML #990

Open
ocomsoft opened this issue Nov 5, 2024 · 2 comments
Open

SUGGESTION: Handle plan HTML #990

ocomsoft opened this issue Nov 5, 2024 · 2 comments

Comments

@ocomsoft
Copy link

ocomsoft commented Nov 5, 2024

I think this project is getting a lot of traction in the Go community, especially for HTMX

As a GoLand user the experience is not the best (Sorry, I appreciate the effort)

What I think would be ideal is if we can write "plain" HTML as much as possible. ie without the "templ" code before and after the actual template. I think what we have already works well and is still required.

I have 2 suggestions

  1. How about we add an "include" command that generate will load the file and include as if the HTML was inline.
package main

templ hello(name string) {
	{{include hello.html}}
}

Where hello.html has plain html with templ mark in it ie

<div>Hello, { name }</div>

This means we can define the imports and the parameters etc as we can now but we can also have our IDE handle the file as a normal HTML with whatever templating code is in there.

  1. Create a new "format" that can be read by generate and pre-processed to create a "templ" file

I am not sure what the best syntax is but a suggestion would be something like this:

<!DOCTYPE html>
<templ:import>"github.com/duke-git/lancet/v2/strutil"</templ:import>
<templ:param>name string</templ:param>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Sample File</title>
</head>
<body>
<h1>
    This is a Sample {{name}}
</h1>
</body>
</html>

My initial proposal is we have some "templ" elements that we can "find" using "golang.org/x/net/html" and process.
The templ:import would be used to create Imports in the Go Code and the templ:param would be used to add params to the templ function. We could use the directory name for the package name or add a templ:package and the function name could be the file name or again add a templ:func etc.

This could be pre-processed into a templ file ie

package directory_name

import "github.com/duke-git/lancet/v2/strutil"
templ Filename(name string) { 
<!DOCTYPE html><html lang="en"><head></head><body>
    <meta charset="UTF-8"/>
    <title>Sample File</title>


<h1>
    This is a Sample {{name}}
</h1>


</body></html>
}

I am not sure how this fits with your philosophy for templ but I am hoping I might have some ideas in here that make sense.
Or maybe I am trying to convert this into something else. I could not find another issue that mentions anything like this so I hope I m not rehashing something that has already been discussed.

@joerdav
Copy link
Collaborator

joerdav commented Nov 5, 2024

Thankyou for the proposal, and taking some time out to submit it so thoroughly!

I agree that the GoLand plugin experience is still sub-optimal, this is mainly down to the core maintainers not using GoLand so struggling to prioritise work in that area.

I can understand the reasoning behind your proposal, you want to be able to write code in HTML files so that you can get the tooling that GoLand provides for HTML editing? One thing we'd need to consider carefully is how this change might impact existing templ tooling, there would be a trade-off there the use of the GoLand HTML tooling for editing would not provide autocomplete for go expressions within the template.

My second thought on this is that the syntax you provided is very different to templ as it is. Our philosophy with the templ "language" is to introduce as little "templ" as possible, it should feel like a combination of go and html, so that it is familiar to new users. I think this change would introduce a separate templ language for people to learn as well as the .templ syntax.

Ideally we would improve the GoLand experience, if you have time to outline issues you are having with it in the issue tracker, or to give a 👍 on any issues that you are experiencing, it'll help us prioritise the problems.

@ocomsoft
Copy link
Author

ocomsoft commented Nov 5, 2024

I appreciate your response. I have not tried the tooling in Vscode so I cannot comment. I was thinking this would be a more generic solution.

My proposal for the "elements" was because I have already developed a quick Proof of concept that takes the html and generates a templ file. I also think we could so something like {{import "somepackage"}} and {{methodname "MyTemplate"}} which would look more templ language like.

Please understand this is not a criticism of the development done for the Goland Plugin. It was more about there is way more tooling for HTML and even HTML with "templating" languages than the other way around :)

My other suggestion which I havent explored alot would be what if we had an {{include "filename.html"}} and it will include the file as if it was inline this way the templ language doesn't change and I can use other tooling on the HTML template. What are your thoughts on that?

Please understand, I am only trying to make this better. I think this will be a key go tech especially with htmx developers.

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

2 participants