This meteorjs package brings the Meteor
namespace into your templates.
So you do not need a number of template helpers by yourself anymore and you can use the same notation to get the Meteor state values even if you write them to javascript or template files.
Let's say you want to show the information about the connection status:
mytemplate.html:
<template "mytemplate">
<span>{{show_status}}</span>
</template>
mytemplate.js:
Template.mytemplate.helpers({
show_status: function() {
return Meteor.status().status;
}
});
mytemplate.html:
<template "mytemplate">
<span>{{Meteor.status.status}}</span>
</template>
That's it. The values are reactive as if you would write your own helpers.
You can add this package to your meteor app like any other package from atmosphere
$ meteor add 4commerce:meteor-namespace-template-helper
You may address the following attributes from Meteor
object in your templates:
Beside the above state attributes you also have access to the complete Meteor.settings.public
object which is synced also between server and clients. Have a look at the special Meteor.settings section in this documentation.
If you also have installed the package accounts-base
these elements are available too:
mytemplate.html:
<template "mytemplate">
<span>{{Meteor.release}}</span>
<span>{{#if Meteor.isClient}}You are on the client{{/if}}</span>
</template>
This meteorjs package allows you also to get access to the objects and values you have stored at Meteor.settings.public within your templates.
You want to show the information given by your settings at your client app.
$ export METEOR_SETTINGS="{ public: { about_info: 'Hello World App', version: '1.0' } }"
$ meteor
Alternative you may use --settings option
$ meteor --settings mysettings.json
mytemplate.html:
<template "mytemplate">
<span>{{Meteor.settings.public.about_info}}</span>
<span>{{Meteor.settings.public.version}}</span>
</template>
You may address your public settings directly within your templates by just using the same path as defined on the Meteor.settings.public element.
mytemplate.html:
<template "mytemplate">
<span>{{Meteor.settings.public.about_info}}</span>
</template>
You also may address the settings values by a dotted string argument. So the next example shows equal options. Make sure that the path this time is relative with starting from Meteor.settings.public
mytemplate.html:
<template "mytemplate">
<span>{{Meteor.settings.public.about_info}}</span>
<span>{{Meteor.settings.public 'about_info'}}</span>
</template>
You may also address deeper elements as normal objects. Let's imaging you have the following settings.json
{
"public": {
"application": {
"version": "1.0",
"author": {
name: "My Name",
email: "mail-address"
}
}
}
}
then you can get those element values in your templates by
<template "mytemplate">
{{#if Meteor.settings.public.application.author}}
<span>{{Meteor.settings.public.application.author.name}}</span>
<span>{{Meteor.settings.public 'application.author.email'}}</span>
{{/if}}
</template>
For a more sophiticated usage, you even may pass another expression to get the name of the config value to show.
The following example will return either the value for about_info
or version
whatever the bool expression of foo is:
mytemplate.html:
<template "mytemplate">
<span>{{Meteor.settings.public what_to_show}}</span>
</template>
Template.mytemplate.helpers({
what_to_show: function() {
return (foo) ? "version" : "about_info"
}
});
We created also a ShortCut package to address the settings elements just by pubSettings
. Please have a look at 4commerce:pubsettings-template-helper if you are interested in.
See: https://github.com/4commerce-technologies-AG/meteor-package-pubsettings-template-helper
In addition, if you are looking for an easy and highly flexible configuration management based on the NODE_ENV environment, you should have a look at the 4commerce:env-settings package.
See: https://github.com/4commerce-technologies-AG/meteor-package-env-settings
In case of support or error please report your issue request. The issue tracker is available at: https://github.com/4commerce-technologies-AG/meteor-package-meteor-namespace-template-helper/issues
Author: Tom Freudenberg, 4commerce technologies AG
Copyright (c) 2015 Tom Freudenberg, 4commerce technologies AG, released under the MIT license