Use variables in head title in SpaceBars

I am trying to set <title>appName {{version}}</title> in the head tag, but doesn’t seem to work, even when I Session.set at the topmost .js file.

Why can’t I do this?

1 Like

Head is not a template (I think) so you can’t use Spacebars in it.

Look at this package for example: https://github.com/DerMambo/ms-seo

1 Like

Looks like an overkill, I guess in meteor we have to set the title dynamically via javascript…

1 Like

I’ll have a look if it’s possible to provide either a package or a patch for Meteor/Blaze/wherever this concern lives so it would stop biting people.

If anyone has any pointers / additional info about this, then please post here or message! Thanks!

2 Likes

Yeah I mean, you don’t have to use the whole package, just look at how they do it

@benjick They actually set the title via a meta tag, not the head->title tag.

Well, actually it’s only document.title = title that sets the title, which is the same as the title attribute

Set some title

<head>
  <title>titletest titleVersion</title>

And than just replace it

  if (Meteor.isServer) {
    	var currentVersion = 314;
    	Meteor.startup(function () {
    		// code to run on server at startup
    		Inject.rawModHtml('setTitle', function(html) {
    			return html.replace( 'titleVersion</title>', 
    				currentVersion+'</title>');
    		});
    	});
    };

any questions? :smiley:
It is not exactly what u were asking, but this way it is not client side, so in theory you can define some stuff during load visible by indexing services etc.

package meteorhacks:inject-initial

1 Like