Rewrite the hacky sidebar template to use a general "tree splice" that recurses when rendering the sub trees.
Use <apply> to recursively invoke the self template.
Haha, I've recently used Dhall to quickly put together small static website and it worked pretty well - using little script that called dhall text on directory with .dhall files with structure matching final routes.
Should this get approved or not I’d be up for volunteering to try this. Haven’t standardised anything before, but I guess it’d involve updating similar files to say this PR https://github.com/dhall-lang/dhall-lang/pull/1062, and maybe the type inference docs/tests also? If anyone else wants to jump in that’s cool, but thought I’d throw my name in the hat all the same.
Well, obviously I'm not going to be switching to Dhall because it is rather primitive for my use case of HTML templates (though I'd love to see if Dhall gets first-class HTML templating support and if so how it will manage to deal with XML).
Is anyone aware of any HTML template library that supports recursion (eg: to render a tree)? While also supporting scoped variable bindings.
Just learned that Heist does: https://github.com/srid/emabook/pull/7/files
Admittedly not a real templating library, but can be used for it: dhall
Haha, I've recently used Dhall to quickly put together small static website and it worked pretty well - using little script that called
dhall text
on directory with.dhall
files with structure matching final routes.My biggest gripe on using dhall for this, is the lack of text operations, not possible to do html escaping
I also used dhall as a "templating library" once (not for html), but having to write out all the tyvars is annoying :(
Mats Rauhala said:
Yeah - should be easy enough to extend it using HS API if we were to write templating engine based on it though
Wait, it seems like there's XML support: https://store.dhall-lang.org/Prelude-v20.1.0/XML/index.html
Yeah, I went through the XML source a while ago. There's no escaping there either :)
Practical concerns aside; It's cool that the XML stuff is based on a recursive tree.
Doesn't Dhalls Text/replace builtin work for that? Like
Text/replace "<" "<"
?Make XSLT Great Again (but in Haskell)
Oh, right, https://discourse.dhall-lang.org/t/expense-proposal-standardize-text-replace-built-in/339/2 this was a thing
Well, obviously I'm not going to be switching to Dhall because it is rather primitive for my use case of HTML templates (though I'd love to see if Dhall gets first-class HTML templating support and if so how it will manage to deal with XML).
Heist is, surprisingly, plenty powerful. This sidebar tree with node-specific state (open, close, active) https://haskell-kb.srid.ca/Syntax/case-of - is generated by this recursive template
And here's the corresponding Haskell code. See how polymorphic it is over the tree type. You can use any
Data.Tree
. https://github.com/srid/emabook/blob/84ee208d174b8f751e98725cd63bb16771597bad/src/Heist/Extra/Splices/Tree.hs#L15-L38https://github.com/dhall-lang/dhall-lang/pull/1174 interesting. The xml escaping was not only a known issue, but something that was fixed in the latest release (today)
Dhall HTML templating in the news,
https://www.reddit.com/r/haskell/comments/n2s8yk/monthly_hask_anything_may_2021/gysz35z/