-
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
Override a context field with nothing #913
Comments
Hi, sorry for such a late reply! I don't see a way to short-circuit withoutField :: String -> Context a -> Context a
withoutField key (Context inner) = Context $ \k a i ->
if k == key
then noResult $ "Field " ++ k ++ " is nullified"
else inner k a i You would then do this: defaultContext `withoutField` "title" How does that sound to you?
I guess you have figured out by now that |
Hey @kirelagin, did you get a chance to look at the above suggestions? |
@kirelagin, ping. |
Apologies for the delay. The workaround wrapper sounds pretty good to me – I can’t remember now how exactly the issue manifested for me, but, I suppose, it would work. As for the docs, I am not exactly sure what the best way to address this would be. Maybe a note/warning could be added to the haddock of the |
Dunno. The doc already says that Hakyll doesn't have a cookbook, and after thinking about it a bit, I don't think I'd add this snippet to one of the existing modules either. So I'll just let it sit here for now, and if a lot of people stumble into this, I can reconsider. |
(Unfortunately, I did not find an easy way to play around with contexts in a repl, so instead of showing the code, I’ll have to describe the issue using words.)
After reading the documentation for
field
, I was under an impression that usingempty
ornoResult
will allow me to “unset” a field in a context, but apparently it does nothing at all.Suppose, I want to create a context that will be the same as
defaultContext
, but without anytitle
field (i.e.$if(title)$
in template should not get triggered). So, naturally, I triedfield "title" (const empty) <> defaultContext
, but it did not work as expected – I still got a title.This has another, in my opinion, very unexpected implication:
boolField "title" (something) <> defaultContext
overrides thetitle
field withTrue
only if the value isTrue
, but if it isFalse
, the value is not overridden at all and remains a (True
-valued) string.The text was updated successfully, but these errors were encountered: