Discussion:
[hakyll] reading template as a string
m***@gmail.com
2017-04-07 14:05:28 UTC
Permalink
Hi,

I'm trying to read template as a String. My goal is to pass custom
template to Pandoc' WriterOptions. Something like:


...

route "xxx" $ do
route $ setExtension "html"
compile $ do
tmpl <- loadBody "templates/tmpl.html"
pandocCompilerWith defaultHakyllReaderOptions $ myWriterOptions tmpl

myWriterOptions :: String -> WriterOptions
myWriterOptions tmpl = defaultHakyllWriterOptions {
writerTemplate = tmpl
}


Unfortunately, I've got runtime error:
[ERROR] Hakyll.Core.Compiler.Require.load: templates/revealjs.html
(snapshot _final) was found in the cache, but does not have the right type:
expected [Char] but got Template

I suppose I have to get content of the template, but I don't know how to do
it (or, maybe there is another option to load template inside Compiler
monad).

--
Regards,
Mike.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Gnoutcheff
2017-04-07 19:04:39 UTC
Permalink
Post by m***@gmail.com
Hi,
I'm trying to read template as a String. My goal is to pass custom
template to Pandoc' WriterOptions.
I'm doing the same thing for a site I'm building. I created a separate
directory for pandoc templates ("templates-pandoc") and I loaded it with

match "templates-pandoc/*" $ compiler getResourceBody

Once you do that, `loadBody "templates-pandoc/some-template.html"` will
get you an `Compiler String`, as desired.

As you may have gathered, the type of `load "some-item"` has to match
the type of the compiler that's been associated with "some-item" (and
this isn't checked until runtime, unfortunately). For Hakyll templates,
the compiler will usually be
`templateCompiler :: Compiler (Item Template)`.

HTH!

Later,
Daniel
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...