PebbleTemplates / pebble

Java Template Engine
https://pebbletemplates.io
BSD 3-Clause "New" or "Revised" License
1.1k stars 168 forks source link

[Feature Request] Fragment/Partial Rendering Support #641

Open TareqK opened 1 year ago

TareqK commented 1 year ago

So The concept here is to allow rendering part of a template, instead of the whole template, by defining a fragments system. This isnt the same as including a template in a template, and the main value is related to the use of pebble in SSR applications. Effectively, instead of passing the template you want to render, like my-template.peb, you would pass my-template.peb#fragment-name, which would only render the relevant section of a template, eg, lets say i have my-template.peb which looks like this

{ % fragment fragment-1 % }
 Hi-There
{ %endfragment%}

{ % fragment fragment-2 % }
Its-a-me
{ %endfragment%}

if I chose to render my-template.peb#fragment-1, i would get

Hi-There

if i choose to render my-template.peb, i would get

Hi There
Its-a-me

so on and so forth

further rationale on the value of this can be found here https://htmx.org/essays/template-fragments/

More than happy to contribute this, if there is room for it. It introduces no breaking changes.

rdehuyss commented 6 months ago

+1 Also in favor of this!