casid / jte

Secure and speedy templates for Java and Kotlin.
https://jte.gg
Apache License 2.0
819 stars 59 forks source link

Layout Syntax Proposal #133

Closed 1cg closed 2 years ago

1cg commented 2 years ago

Hi There,

Love your templating system! Glad to see someone still innovating in this space too.

Was wondering if you might consider a slightly different layout syntax. Right now we have this:

@import org.example.WelcomePage
@param WelcomePage welcomePage

@template.layout.page(
    page = welcomePage,
    content = @`
        <p>Welcome, ${welcomePage.getUserName()}.</p>
    `,
    footer = @`
        <p>Thanks for visiting, come again soon!</p>
    `
)

which makes a ton of sense. But it's a little ugly having to indent the markup like that. What about an alternative syntax that captures the same idea:

@import org.example.WelcomePage
@param WelcomePage welcomePage
@layout template.layout.page(page=welcomePage)

@layout:content
   <p>Welcome, ${welcomePage.getUserName()}.</p>

@layout:footer
  <p>Thanks for visiting, come again soon!</p>

I'm not settled on this particular syntax, it's just an example, but the idea is to linearize the content/markup so it's easier to parse visually and you don't have small little back-tics and commas interspersed throughout.

casid commented 2 years ago

Welcome @1cg and thanks for the heads up!

I agree, the current is rather technical, but it offers a lot of possibilities. And it also goes really well with the IntelliJ plugin.

For example, in case you have the same content for two layout slots? You can easily do this:

!{var sameContent = @`<p>Hello there</p>`;}

@template.my.layout(content = sameContent, footer = sameContent)

Or, this content is provided by a Java method? Also works very well:

@template.my.layout(content = page.getContent(), footer = @`foo`)

Changing to a different syntax would be very hard for the plugin to adjust to. Initially jte had very similar layout syntax to what you suggested: https://github.com/casid/jte/blob/f9951d5a4e264a58c831add2b37902ab605fed22/DOCUMENTATION.md#layouts This was changed due to the above limitations and because of in some cases content blocks were needed in non-layout template calls as well.

1cg commented 2 years ago

Would adding an end or some sort of follow to the syntax help?

It's pretty incredible that you are managing both a template system and an IJ plugin (I am a huge IJ fan). I'm sure the plugin is at least twice the size of the templating code!

1cg commented 2 years ago

oh, wow, this syntax is exactly what I was looking for!

https://github.com/casid/jte/blob/f9951d5a4e264a58c831add2b37902ab605fed22/DOCUMENTATION.md#layouts

If I'm willing to forego a perfect editor experience can I use it?

1cg commented 2 years ago

and, since I'm spamming you anyway, is there a chat system you use for talking about jte? We use discord for htmx:

https://htmx.org/discord

casid commented 2 years ago

@1cg no, unfortunately that syntax doesn't work anymore :-)

And no, there's no chat system atm. I'm on discord from time to time, so that might work.

Also, I'm very excited about htmx, once I have a fitting project I'll definitely gonna give it a try together with jte.

1cg commented 2 years ago

That's awesome to hear Andreas. If you have time at some point I would love to chat.

I have a new project bubbling along that is going to bring htmx to the JVM (I am a java developer who has spent a decade in rails) and I like jte the most of all the template systems I have seen. Would love to chat about the project, understand where you are going with it and maybe even contribute if I can be of help.

You can find me on the htmx discord and DM me, or email me at carson at bigsky dot software. Thank you! You can close this issue out if you like!

casid commented 2 years ago

Thank you! I've sent you a message on discord :-)