-
Notifications
You must be signed in to change notification settings - Fork 409
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
Partial with arguments #806
Comments
Judging by this line, But I think the above can be replaced with:
…and then in (untested!) Haskell code: let ctxFst = \item -> fst (itemBody item)
let ctxSnd = \item -> snd (itemBody item)
let sectionContext = field "sectionTitle" ctxFst <> field "sectionBody" ctxSnd
let postsContext = listField "sections" sectionContext $ do
section1 <- makeItem ("My first section", "My first section body")
section2 <- makeItem ("My second section", "My second section body")
return $ [section1, section2] In other words:
Does that solve the issue, @tobiasBora? |
Thanks for your answer. But unfortunately, I'd prefer to have the list contained in the html file directly to keep the html code at the same place. But I discovered that it's possible to send any function (taking as input a list of strings) in the context, so I created my own cooked solution. I think it's possible to improve it by interpreting the input as JSON directly (it would allow to send lists of items that way). The only issue I have is that I don't think it's possible from
And now you can use it that way: put in your html file something like:
and create your template accordingly:
@jaspervdj : Are you open to pull requests so that I can integrate this command into the project? I don't see lots of PR merged (included my last minor PR), and I'm not sure if it's just a lack of time to integrate them, or if you don't want any PR. |
Oh, that's nifty! I'm glad you resolved that, @tobiasBora. I doubt this should be a part of Hakyll proper, though. Feels like a pretty specialized function to me. @jaspervdj If you need a hand with merging PRs, please add me as a collaborator. I can field the simpler ones, so you can concentrate on just the intrusive ones whenever you have time. |
Why is it specialized? It looks to me quite common to include templates and wanting to change its environment... To me, its a bit like having function without arguments: just useful to avoid copy/paste/repetitions, but pretty useless otherwise. Most template systems do have such feature, for example Jinga2/EDE have:
For example, now, I need a JSON version of it because I need to loop in my template in order to create a menu. And since the templating system does not allow to create "variables" I need to rely on partials + hack. This also brings me to another question: is it possible to integrate with other templating systems like EDE instead of the default one? Notably, how am I supposed to do the compile step? Also, stupid question, but it's not possible to access to the parent context when you loop into a list right? Like if my context contains
to get:
right? |
Because it violates Hakyll's separation of data (which should be in Note that Hakyll has a little ecosystem of its own. A function need not be in Hakyll proper to be re-used by others ;)
It sure looks like it: there are hakyll-shakespeare and hakyll-blaze-templates already, so you can probably leverage ede to create the same. Note too that there's a Jinja2 re-implementation called gigner.
Sounds like #490. |
And why a template could not provide some data to another template? It would allow reusing of components.
People usually take what is simpler to do, and in most cases it's simpler to just write a bit of code that do not respect the DRY guideline, or that is not super well customized, than writing technical code to fix a library. But if you like, I can give a few examples of websites that could benefit from having
When the data does not come from the template, like for citations in articles, I found some nice ideas and some less nice:
Thanks for the links, I'll try to see if I can get inspired. So anyway, for people interested, I just created a function to call a partial with arguments coming from a json file. You just need to add a serate rule to keep track of the json file (see #809).
and then:
|
Hello,
I'd like to define a block an html code that should be called quite often. To that end, I would like to create a partial
myblock.html
with something like:and I'd like to insert
myblock.html
into other templates using something like:However, I can't find in the documentation how to do that. Is it a missing feature, or an undocumented feature? In any case, would it be possible to solve that issue?
Thanks!
The text was updated successfully, but these errors were encountered: