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

Why bother with template directives? #25

Closed
cowwoc opened this issue Nov 12, 2023 · 4 comments
Closed

Why bother with template directives? #25

cowwoc opened this issue Nov 12, 2023 · 4 comments

Comments

@cowwoc
Copy link

cowwoc commented Nov 12, 2023

Instead of trying to recreate a programming language using template directives, why not just use normal Java code to generate and return HTML code? This is what React Remix does and it's way easier to use and read.

@floodfx
Copy link
Owner

floodfx commented Nov 14, 2023

Hey there @cowwoc!

What "normal" java code generates and returns HTML? Like a different template engine? Undead uses StringTemplate mostly because it is a templating engine that makes it easy to get the data structure we need. Most other template engines don't provide access to the "raw" data structures behind the templates themselves - rather they just return the rendered string which isn't what we need.

The template directives are completely optional so there is nothing stopping you from using embedded expressions in your StringTemplates.

That said, StringTemplate-based HTML templates are so new that I think it is worth experimenting with tools that might make them easier to build. I'd suggest you try them out more extensively and see what you think. Maybe compare / contrast some template examples?

I don't understand your point re: React Remix. Remix is a javascript-based framework which is a completely different language than Java with different package manager, build chain, etc. The idea with Undead is you only need to write Java. No javascript. No FE vs BE, etc...

@floodfx
Copy link
Owner

floodfx commented Nov 14, 2023

Happy to continue convo but closing the issue.

@floodfx floodfx closed this as completed Nov 14, 2023
@cowwoc
Copy link
Author

cowwoc commented Nov 14, 2023

Forgetting the programming platform for a second, Remix lets you build up an HTML document using Javascript code. Example: https://stackoverflow.com/q/77306709/14731 or ${cat} in https://css-tricks.com/the-basics-of-remix/

You can literally build up the HTML script using the full power of Javascript or calculate values in JS and embed them using ${foo}.

I have nothing against embedding simple values in code (e.g. ${foo}). I'm just objecting to the idea of moving for-loops into the templating engine. I am advocating that operations of any kind should live outside of the content.

@floodfx
Copy link
Owner

floodfx commented Nov 14, 2023

Hey @cowwoc. Remix's own tutorial has if else statements, "ternary" operators, and Array.map calls embedded in their templates. See: https://remix.run/docs/en/main/start/tutorial

JSX (and TSX) utilize boolean logic and looping (via map) basically in all but the most simple templates.

Most (all?) template languages have ways to implement boolean logic and loops at a minimum. Again, you don't have to use the directives in Undead but I think it'd be almost impossible to build anything non-trivial without boolean logic and looping.

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