Giter Site home page Giter Site logo

Comments (6)

ismay avatar ismay commented on August 11, 2024

Try this:

  1. I'd move all layouts outside of ./src. Otherwise you might end up with some unwanted recursiveness. Move them to ./layouts for example (and remove the directory option).
  2. Remove the partials option. It isn't necessary for swig includes.
  3. Put your test.html include in ./layouts. Swig includes are relative to the layouts directory (I believe), so that way {% include "test.html" %} should work.

Now it should work. Let me know.

from layouts.

jeromecoupe avatar jeromecoupe commented on August 11, 2024

Many thanks for coming back to me so quickly. Much appreciated.

  1. Everything out of ./src (typos in my original issue). I have left the directory option since I like to be explicit (team members are not familiar with Metalsmith)
  2. and 3. Done. It does work like that. That was the issue I was having. Whatever I did before, it was always the ./layouts folder that was called for includes

Couple of related questions

  1. So Swig includes are always relative to the layouts directory? Is there no way to have layouts and includes in separate directories w/ Swig? I realise this is just cosmetic but I am used to Twig where this is definitely possible.
  2. With metalsmith, is it possible to use the usual {% block %}{% endblock %} and {% extends 'templates/default.html' %} tags instead of Yaml front matter and {{ content }} tag ? If so, how do you do that ? I haven't managed to get it working.

Again, thanks for your help.

from layouts.

ismay avatar ismay commented on August 11, 2024

So Swig includes are always relative to the layouts directory?

I'd have to test it to be sure (because each templating engine differs), but it's either relative to the layouts dir, or the current layout. Not certain which of those two it is (it ultimately depends on consolidate's implementation).

Is there no way to have layouts and includes in separate directories w/ Swig?

You could, but then it would be something like {% include "../includes/test.html" %} instead of {% include "test.html" %} because of the relative path.

With metalsmith, is it possible to use the usual {% block %}{% endblock %} and {% extends 'templates/default.html' %} tags instead of Yaml front matter and {{ content }} tag ?

Definitely. You can use both. Basically all that the yaml front matter does is define local variables. And the contents variable is just that, a variable. That variable is passed to the selected layout and the result is compiled.

But that being said; if you're going to use swig I'd recommend metalsmith-in-place. Metalsmith-layouts is just meant as a shim for languages that don't support template inheritance, like handlebars.

Check out https://github.com/ismay/ismaywolff.nl for an example. I'm using nunjucks, which is very similar to swig, so you should be able to adapt it to your liking. Let me know if that helps.

from layouts.

ismay avatar ismay commented on August 11, 2024

Oh, by the way, metalsmith-in-place render things a little differently, so when using extends and includes paths are relative to the root of the project (since there are no layouts). You'll see that in my repo.

Also, https://github.com/superwolff/boilerplate-in-place and https://github.com/superwolff/boilerplate-layouts are good starting points for both plugins.

from layouts.

jeromecoupe avatar jeromecoupe commented on August 11, 2024

ok. Will have a look. Still not very clear to me how to use that with the CLI but I guess I can figure it out with the various links you provided. Thanks again ! Coming from Jekyll here and the Metalsmith doc is rather sparse ;o)

That being said, I like it so far.

from layouts.

ismay avatar ismay commented on August 11, 2024

Coming from Jekyll here and the Metalsmith doc is rather sparse ;o)

Yeah I know :). It can be frustrating but it's worth the effort I think. I'll update the readme to address your questions.

Also, the boilerplates use the javascript api, but the basic configuration should work for the cli just as well. And if you're going to use extends don't forget to use metalsmith-filenames.

I'll close this, but feel free to let me know if you have any further questions!

from layouts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.