Use variables in head title in SpaceBars


#1

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?


#2

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


#3

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


#4

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!


#5

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


#6

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


#7

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


#8

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