Is there a way to check if package exists?


#1

Tried to google about it and didn’t find a way to check in server side code if some package is installed or missing. Any suggestions how to achieve this functionality?


#2

There’s not really an official way but you can check for the existence of Package['author:package-name'].


#3

Thanks mate! It works like a charm :slight_smile:


#4

Is there a way to do this in a Blaze template?

I tried this, but it did not work:

{{#if Package["my:package"] }}
...
{{/if}}

#5

Just register a global helper. Something as simple as this:

Template.registerHelper('packageIsInstalled', function (packageName) {
    return !!Package[packageName];
});

Then in your HTML use it like this:

{{#if packageIsInstalled 'my:package'}}
...
{{/if}}

#6

Thanks. It seems a bit strange, though, that this would work, as the syntax in the template is exactly the same as in Package["my:package"].


#7

Sorry, my bad. Should be:

{{#if packageIsInstalled 'my:package' }} ... {{/if}}

I edited my original reply as well, for those in a rush.


#8

Ah, thanks :slight_smile: