Open achou11 opened 2 years ago
ah maybe this will help?
https://git.sr.ht/~bakpakin/temple/tree/master/item/test/templates/hop.temple
This almost works but can't get the :_slot
to actually render when building
# base.temple
<html>
{{ (get-in args [:_slot]) }}
</html>
# log.temple
<p>Some log</p>
# wrapped.temple
{$
(import ./base :as base)
(import ./log :as log) $}
{% (base/render-dict (merge args {:_slot (log/render-dict args)})) %}
Wondering what I'm missing :thinking:
Unfortunately, I think the structure you’re looking for isn’t a feature of Temple. I did a bit of searching - I think jinja refers to that usage as ‘template inheritance’. I asked after that feature myself and I think it’s out of scope for Temple.
In practice , I just include a header and a footer separately , rather than a single skeleton with the header and footer content, and a hole called ‘content’. But I could imagine for more complex layouts, that approach might not scale.
Under the hood temple is just string macros… I wouldn’t be surprised if you could magic a way up to do codegen on individual temple templates!
Unfortunately, I think the structure you’re looking for isn’t a feature of Temple. I did a bit of searching - I think jinja refers to that usage as ‘template inheritance’. I asked after that feature myself and I think it’s out of scope for Temple.
In practice , I just include a header and a footer separately , rather than a single skeleton with the header and footer content, and a hole called ‘content’. But I could imagine for more complex layouts, that approach might not scale.
makes sense! do you think the approach I'm trying in my previous comment may be an option? (assuming I figure out how to actually make it work 😅)
Under the hood temple is just string macros… I wouldn’t be surprised if you could magic a way up to do codegen on individual temple templates!
probably a way of doing it but my lack of knowledge fails me for now 😅
makes sense! do you think the approach I'm trying in my previous comment may be an option? (assuming I figure out how to actually make it work sweat_smile)
It might need more metaprogramming. I think at least some of this is happening in runtime when it needs to happen at macro expansion time.
That said, I'm mildly nerdsniped and might try it out this evening!
@subsetpark was poking around Mendoza and looks like it supports template inheritance using :template
! (see section about {{ node }}
)
https://bakpakin.github.io/mendoza/templating.html
Haven't taken a look at the implementation but maybe something to look at if you feel curious again 😄
Todo: look into whether pepe's example is what I'm looking for:
https://git.sr.ht/~pepe/neil/tree/master/item/templates/app.temple
https://git.sr.ht/~pepe/neil/tree/master/item/neil/watch/init.janet
https://janet-lang.org/api/spork/index.html#spork/misc/capout
Based on examples I've seen provided by Bagatto + Temple, there doesn't seem to be a way to define a layout that can be referenced from another template so that it "wraps" it. Instead, you have to piece together fragments and include them everywhere e.g.
what i want is something like this:
and then create a template whose content is inserted into the
injected_content
inbase.temple
, e.g.