All Projects → metalsmith → Metalsmith Layouts

metalsmith / Metalsmith Layouts

🌼 A metalsmith plugin for layouts

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Metalsmith Layouts

Plush
The powerful template system that Go needs
Stars: ✭ 623 (+471.56%)
Mutual labels:  templating
Generate Template Files
A simple generator to create custom template files for any application
Stars: ✭ 60 (-44.95%)
Mutual labels:  templating
Metalsmith React Templates
A metalsmith plugin to render files using React / Preact / JSX based templates.
Stars: ✭ 90 (-17.43%)
Mutual labels:  templating
Dotdrop
Save your dotfiles once, deploy them everywhere
Stars: ✭ 813 (+645.87%)
Mutual labels:  templating
Yglu
Yglu ᕄ !? - YAML glue for structural templating and processing
Stars: ✭ 51 (-53.21%)
Mutual labels:  templating
Pebble Intellij
Pebble support for IntelliJ IDEA
Stars: ✭ 68 (-37.61%)
Mutual labels:  templating
Levant
An open source templating and deployment tool for HashiCorp Nomad jobs
Stars: ✭ 510 (+367.89%)
Mutual labels:  templating
Htm.py
JSX-like syntax in plain Python
Stars: ✭ 102 (-6.42%)
Mutual labels:  templating
Metalsmith In Place
🏙️ A metalsmith plugin for in-place templating
Stars: ✭ 52 (-52.29%)
Mutual labels:  templating
Gomplate
A flexible commandline tool for template rendering. Supports lots of local and remote datasources.
Stars: ✭ 1,270 (+1065.14%)
Mutual labels:  templating
Carvel Ytt
YAML templating tool that works on YAML structure instead of text
Stars: ✭ 816 (+648.62%)
Mutual labels:  templating
Cv Maker
simple elegant markdown based resumes
Stars: ✭ 1,003 (+820.18%)
Mutual labels:  templating
Fluidcontent
TYPO3 extension Fluidcontent: Fluid Content Element Engine
Stars: ✭ 82 (-24.77%)
Mutual labels:  templating
Faas Cli
Official CLI for OpenFaaS
Stars: ✭ 633 (+480.73%)
Mutual labels:  templating
Vuerecipe
A recipe for using Buffalo & Vue.js
Stars: ✭ 95 (-12.84%)
Mutual labels:  templating
Rocker
Java 8 optimized, memory efficient, speedy template engine producing statically typed, plain java objects
Stars: ✭ 609 (+458.72%)
Mutual labels:  templating
Awesome Twig
A curated list of amazingly awesome Twig extensions, snippets and tutorials
Stars: ✭ 63 (-42.2%)
Mutual labels:  templating
Plot
A DSL for writing type-safe HTML, XML and RSS in Swift.
Stars: ✭ 1,722 (+1479.82%)
Mutual labels:  templating
Scriban
A fast, powerful, safe and lightweight scripting language and engine for .NET
Stars: ✭ 1,360 (+1147.71%)
Mutual labels:  templating
Askama
Type-safe, compiled Jinja-like templates for Rust
Stars: ✭ 1,255 (+1051.38%)
Mutual labels:  templating

metalsmith-layouts

build status coverage status greenkeeper

A metalsmith plugin for layouts

This plugin allows you to wrap your files in a template (a layout) and abstract repetitive html. The plugin will pass the contents of your files to the layout as the variable contents, and renders the result with the appropriate templating engine. It uses the file extension of your layout to infer which templating engine to use. So layouts with names ending in .njk will be processed as nunjucks, .hbs as handlebars, etc.

If you want to process templating syntax in your files, instead of wrapping them in a template, you can use metalsmith-in-place. For usage examples check out our wiki. Feel free to contribute an example if anything is missing, or update the existing ones. For support questions please use stack overflow or our slack channel. For templating engine specific questions try the aforementioned channels, as well as the documentation for jstransformers and your templating engine of choice.

How does it work

Under the hood this plugin uses jstransformers to render your layouts. Since there are over a 100 jstransformers we don't install them automatically, so you'll need to install the jstransformer for the language you want to use.

For example, to render nunjucks you would install jstransformer-nunjucks, to render handlebars you would install jstransformer-handlebars, etc. The plugin will then automatically detect which jstransformers you've installed. See the jstransformer organisation for all available jstransformers and this dictionary to see which extensions map to which jstransformer.

Installation

$ npm install metalsmith-layouts

Options

You can pass options to metalsmith-layouts with the Javascript API or CLI. The options are:

  • default: optional. The default layout to apply to files.
  • directory: optional. The directory for the layouts. The default is layouts.
  • pattern: optional. Only files that match this pattern will be processed. Accepts a string or an array of strings. The default is **.
  • engineOptions: optional. Use this to pass options to the jstransformer that's rendering your layouts. The default is {}.
  • suppressNoFilesError: optional. By default metalsmith-layouts will exit with an error if there aren't any files to process. Enabling this option will suppress that error.

default

The default layout to use. Can be overridden with the layout key in each file's YAML frontmatter, by passing either a layout or false. Passing false will skip the file entirely.

If a default layout has been specified, metalsmith-layouts will apply layouts to all files, so you might want to ignore certain files with a pattern. Don't forget to specify the default template's file extension. So this metalsmith.json:

{
  "plugins": {
    "metalsmith-layouts": {
      "default": "default.hbs"
    }
  }
}

Will apply the default.hbs layout to all files, unless overridden in the frontmatter.

directory

The directory where metalsmith-layouts looks for the layouts. By default this is layouts. So this metalsmith.json:

{
  "plugins": {
    "metalsmith-layouts": {
      "directory": "templates"
    }
  }
}

Will look for layouts in the templates directory, instead of in layouts.

pattern

Only files that match this pattern will be processed. So this metalsmith.json:

{
  "plugins": {
    "metalsmith-layouts": {
      "pattern": "**/*.html"
    }
  }
}

Would process all files that have the .html extension. Beware that the extensions might be changed by other plugins in the build chain, preventing the pattern from matching. We use multimatch for the pattern matching.

engineOptions

Use this to pass options to the jstransformer that's rendering your templates. So this metalsmith.json:

{
  "plugins": {
    "metalsmith-layouts": {
      "engineOptions": {
        "cache": false
      }
    }
  }
}

Would pass { "cache": false } to the used jstransformer.

suppressNoFilesError

metalsmith-layouts exits with an error if it can’t find any files to process. If you’re doing any kind of incremental builds via something like metalsmith-watch, this is problematic as you’re likely only rebuilding files that have changed. This flag allows you to suppress that error.

Note that when this option is turned on, if you're logging debug messages, you’ll still see a message denoting when there aren't any files for metalsmith-layouts to process.

FAQ

I want to use handlebars partials and or helpers.

Use metalsmith-discover-partials and metalsmith-discover-helpers.

I want to change the extension of my templates.

Use metalsmith-rename.

My templating language requires a filename property to be set.

Use metalsmith-filenames.

Errors and debugging

If you're encountering problems you can use debug to enable verbose logging. To enable debug prefix your build command with DEBUG=metalsmith-layouts. So if you normally run metalsmith to build, use DEBUG=metalsmith-layouts metalsmith (on windows the syntax is slightly different).

No files to process

There are several things that might cause you to get a no files to process error:

  • Your pattern does not match any files
  • None of your files pass validation, validation fails for files that:
    • Have no layout
    • Have a layout without an extension
    • Are not utf-8
    • Have a layout that needs a jstransformer that hasn't been installed

Credits

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].