Comments (6)
Try this:
- 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 thedirectory
option). - Remove the partials option. It isn't necessary for swig includes.
- Put your
test.html
include in./layouts
. Swig includes are relative to thelayouts
directory (I believe), so that way{% include "test.html" %}
should work.
Now it should work. Let me know.
from layouts.
Many thanks for coming back to me so quickly. Much appreciated.
- 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) - 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
- 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.
- 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.
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.
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.
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.
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)
- Cannot include a handlebars layout with a partial HOT 5
- Make errors more descriptive
- Add debug logging
- Update readme and package info
- Version 10 of node.js has been released
- Update after move
- Add suppressNoFilesError flag
- Enable greenkeeper HOT 4
- Improve documentation
- Not working with ECT templates after upgrading from 1.8.1 HOT 3
- Supporting async-only jstransformers HOT 2
- error message missing current file name HOT 1
- From v2.0.0 the metalsmith example static-site is not working HOT 3
- templates should have access to the raw "contents" of other files HOT 5
- Ignoring the output format specified in the jstransformer HOT 5
- Loosen dependency on jstransformers HOT 2
- Align with core plugin setup
- Use metalsmith.match instead of multimatch
- v2.5.0 breaks integration with metalsmith-watch HOT 6
- `pattern` option is not passed in `engineOptions`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from layouts.