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

Made inner loops have access to outer loop values #726

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ilyakooo0
Copy link

If my outer loop in a template produces a value that I want to use in my inner loop, I get a Missing field error.

This gives inner loops access to outer loop values and allows inner loops to override them.

@jaspervdj
Copy link
Owner

This looks good, thanks for the PR! Is it possible to update this with:

  1. An additional comment in Hakyll.Web.Template.Context.listField, explaining how the contexts are combined
  2. A test that reads a value from the outer context

@ilyakooo0
Copy link
Author

Sure

@bergus
Copy link
Contributor

bergus commented Aug 26, 2019

I like it, had to do something quite similar in f49d972 (part of #620). Maybe this combineContexts function shouldn't be just local, but exposed in Context.hs?
Maybe the Context data type needs some general reworking though, if it is supposed to hold some information about an Item.

@ilyakooo0
Copy link
Author

Yeah, I thought about exporting it. I thought it wasn't useful enough.

It sounds like a good idea. Now.

I'm a little overwhelmed right now, will finish the pull request in a couple days.

@ilyakooo0 ilyakooo0 changed the title Made inner loops have access to outer loop values [WIP] Made inner loops have access to outer loop values Aug 26, 2019
@bergus
Copy link
Contributor

bergus commented Aug 26, 2019

I guess for the API I would prefer a simple

bindItem :: Context a -> Item a -> forall b. Context b
-- or
bindContext :: Item a -> Context a -> forall b. Context b

(not sure which one is better?) over a three-parameter and non-descriptive combineContexts function.

You could then write

ListField c xs -> do
    sep <- maybe (return "") go s
    bs  <- mapM (applyTemplate' b $ c <> bindItem context x) xs
    return $ intercalate sep bs

@ilyakooo0 ilyakooo0 changed the title [WIP] Made inner loops have access to outer loop values Made inner loops have access to outer loop values Aug 29, 2019
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

Successfully merging this pull request may close these issues.

None yet

3 participants