Created
February 8, 2017 17:47
-
-
Save kodie/126ca19c8a5a918ccddab1c4348aae8b to your computer and use it in GitHub Desktop.
Meteor template helper to access public settings
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.registerHelper('meteorSettings', function(settings) { | |
var setting = Meteor.settings.public; | |
if (settings) { | |
var eachSetting = settings.split('.'); | |
for (i = 0; i < eachSetting.length; i++) { | |
setting = setting[eachSetting[i]]; | |
} | |
} | |
return setting; | |
}); |
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"> | |
<!-- | |
Basically the same as doing this: (except you can't do this) | |
{{#if Meteor.settings.public.instagram.access_token}} | |
--> | |
{{#if (meteorSettings 'instagram.access_token')}} | |
<div class="instagram"></div> | |
{{/if}} | |
<!-- | |
You can also set Meteor.settings.public to a variable to access multiple settings | |
--> | |
{{#let settings=meteorSettings}} | |
{{settings.instagram.access_token}} | |
{{/let}} | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment