Created
October 29, 2019 17:35
-
-
Save kodie/d3eabaf42b6244fa3cf1a87d7b47f89f to your computer and use it in GitHub Desktop.
Meteor - Display inline SVG content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template name="Home"> | |
{{> Svg svg='my-svg'}} | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template name="Svg"> | |
{{{svg}}} | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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