Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
eleventy-plugin-svg-contents
Advanced tools
A plugin for 11ty to take an SVG and provide the contents of that file to a template
An Eleventy universal plugin to grab the contents of an SVG file to allow for embedding in your template with all the power of SVG.
Available on npm.
npm install eleventy-plugin-svg-contents --save
Open up your Eleventy config file (probably .eleventy.js
) and add the plugin:
const svgContents = require("eleventy-plugin-svg-contents");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(svgContents);
};
In your (Nunjucks, Liquid or Handlebars) templates, use the following syntax to grab the contents from any SVG in your project path:
// nunjucks/liquid
{{ 'path/to/file.svg' | svgContents }}
// handlebars
{{{svgContents 'path/to/file.svg' }}}
Quick note: You may need to pass another filter after to have this render as html. In Nunjucks, you'll add | safe
to the end.
You can append the svg
class with the class
option.
// Nunjucks
{{ 'path/to/file.svg' | svgContents("extra-class-one extra-class-two") }}
// Liquid
{{ 'path/to/file.svg' | svgContents: "extra-class-one extra-class-two" }}
// Handlebars
{{{svgContents 'path/to/file.svg' "extra-class-one extra-class-two" }}}
If you want to use an element selector other than SVG (or want to select a specific piece of an SVG) you can use an optional second argument to provide a selector for the element in your SVG file. Any selector strings will work (classes, ids, attr, element).
Due to limitations of Liquid and Handlebars, you'll need to have a placeholder string for the optional class name argument.
// Nunjucks
{{ 'path/to/file.svg' | svgContents("", "symbol") }}
{{ 'path/to/file.svg' | svgContents("add-class", "#byId") }}
// Liquid
{{ 'path/to/file.svg' | svgContents: "", "symbol" }}
{{ 'path/to/file.svg' | svgContents: "add-class", "#byId" }}
// Handlebars
{{{svgContents 'path/to/file.svg' "" "symbol" }}}
{{{svgContents 'path/to/file.svg' "add-class" "#byId" }}}
svgContents
: Grabs the xml from an SVG and passes it to your template. Voila! Instant embedded SVG from a file!stripTitle
: A filter to strip the <title>
that often comes with SVGs and can cause havoc with SEO.FAQs
A plugin for 11ty to take an SVG and provide the contents of that file to a template
The npm package eleventy-plugin-svg-contents receives a total of 375 weekly downloads. As such, eleventy-plugin-svg-contents popularity was classified as not popular.
We found that eleventy-plugin-svg-contents demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.