bakpakin / mendoza

A Static Site Generator
https://bakpakin.github.io/mendoza/
MIT License
60 stars 17 forks source link

Including templates into templates #9

Closed pepe closed 4 years ago

pepe commented 4 years ago

In the documentation on page https://bakpakin.github.io/mendoza/templating.html, you mention you can include other template by just adding struct with the :template key and path to template as string value. But when I try it with {{ {:template "menu.html"} }} I receive error:

build error: expected integer key in range [0, 9), got @"<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <title>Some</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"viewport\" content=\"width=device-width\">\n    <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/@exampledev/new.css@1/new.min.css\">\n    <link rel=\"stylesheet\" href=\"https://fonts.xz.style/serve/inter.css\">\n  </head>\n  <body>\n    <header><h1>Some</h1></header>\n    "
  in render [/usr/local/lib/janet/mendoza/render.janet] on line 66, column 11
  in _mendoza-template [templates/index.html] on line 1, column 68
  in render [/usr/local/lib/janet/mendoza/render.janet] (tailcall) on line 66, column 11
  in render-page [/usr/local/lib/janet/mendoza/init.janet] on line 139, column 7
  in build [/usr/local/lib/janet/mendoza/init.janet] on line 154, column 5

And indeed in the render function, it is expecting the value to be template function. What am I doing wrong?

I am using my templates under the /templates subfolder. Here is the reproduction repository: https://github.com/pepe/mendtest

pepe commented 4 years ago

So the solution I have found is to (use mendoza/template) and then change the value to of the :template key to (from-file "menu.html") as can be seen in this commit https://github.com/pepe/mendtest/commit/1f916746f87d30e73941d68d2a601db066c3c629.

It works but is not very elegant :-) and I am not sure where to put the check and the fix into the Mendoza code

bakpakin commented 4 years ago

I think the documentation needs to be updated here and we should use the current functionality, which is that render expects only template functions. I think it is best for rendering to not mix module loading as well, which is why the change was made in the first place.

However, it would be nice to provide a macro or function for the above shorthand, maybe something like

{{ (template-include "main.html") }}

That would be the same as

{{ {:template (require "main.html")} }}

or something similar.

pepe commented 4 years ago

It makes sense. Should I try to come with the solution? And fix the documentation?

Thank you for the explanation.