Skip to content

Instantly share code, notes, and snippets.

@kodie
Created October 29, 2019 17:35
Show Gist options
  • Save kodie/d3eabaf42b6244fa3cf1a87d7b47f89f to your computer and use it in GitHub Desktop.
Save kodie/d3eabaf42b6244fa3cf1a87d7b47f89f to your computer and use it in GitHub Desktop.
Meteor - Display inline SVG content
<template name="Home">
{{> Svg svg='my-svg'}}
</template>
<template name="Svg">
{{{svg}}}
</template>
Template.Svg.helpers({
svg: () => {
if (Template.instance() && Template.instance().svg) {
return Template.instance().svg.get()
}
}
})
Template.Svg.onCreated(() => {
let instance = Template.instance()
if (instance.data.svg) {
instance.svg = new ReactiveVar()
Meteor.call('getSvg', instance.data.svg, (err, contents) => {
if (!err) instance.svg.set(contents)
})
}
})
Meteor.methods({
getSvg: svg => Assets.getText('svg/' + svg + '.svg')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment