Meteor 1.3 + SSR + Blaze --> why is Template undefined? [solved]

Hi there, fellow Space travelers. I’m currently trying to create a pdf document from a html page following mainly @ryanswapp great tutorial Generate a PDF from Dynamic Data in Meteor.js.
Everything works ok so far, but I’m not able to add Template helpers to my compiled Template.
Here’s my code:

/imports/server/generate_pdf.js

[...abbreviated for clarity ...]
import { Template } from 'meteor/templating'
import { SSR } from 'meteor/meteorhacks:ssr';
import {moment}  from 'meteor/momentjs:moment';

let generatePdf = () => {
	let fut = new Future();
	let css = Assets.getText('style.css');

	SSR.compileTemplate('layout', Assets.getText('layout.html'));
	SSR.compileTemplate('cv_pdf', Assets.getText('cv_pdf.html'));
    
    **//this throws the following error message: TypeError cannot read property 'cv_pdf' of undefined!!**
	Template.cv_pdf.helpers({
		formattedBirthday(date) {
			return moment(date).format('MMMM Do YYYY');
		}
	});
		
	[...abbreviated for clarity...]
	let html_string = SSR.render('layout', {
		css: css,
		template: "cv_pdf",
		data: resume
	});

	[...abbreviated for clarity ...]
	return base64String;	
}

The template lies in private/ folder.
I’m running on meteor@1.3, meteorhacks:ssr@2.2.0,
Is this a bug in meteorhacks:ssr? I could get away by re-building the resume object by hand before inserting but that would be tedious as it has a fairly complicated structure.

So any help would be highly appreciated and I will praise you the whole weekend!
Thank you!

Hi @stonjarks ! Glad you liked the tutorial :slight_smile: The error your are getting is a result of Blaze not being available on the Server. This is where the meteorhacks:ssr package comes into play. I haven’t yet migrated my app to the 1.3 import/export structure so I’m not entirely sure that this will work but I think you can solve your problem by doing this:

import { SSR, Template } from 'meteor/meteorhacks:ssr';

and then removing the meteor/templating one. Give it a try and let me know if it works!

2 Likes

@ryanswapp Thank you, you saved my weekend! I owe you a beer!
Works perfect!
Meteor’s inport/ export structure is still hard for me to get my head around, ecspecially the different approaches of third -party packages.

Glad to hear it’s working! Ya there are some tricky issues like Tabular and other packages not working with the new structure :grimacing: Fun little dance we have to do every time a major update comes…

Just want to chime in and give some pointers on import export. If this seems rudimentary please forgive me. Basically think about your code as components. For example lets say you have a hero slider. You wouldn’t load all the images or even all the code for the slider on every page if you wanted to just control the slider right. So if you were to create a slider component where only the bits of code that the slider needs to function is only included ( ColdFusion oldie ) on the specific component you want to use. So you would import that bit of code to your slider component thus keeping the global scope clean and only loading code you need and where you need it.

To really wrap your head around modules you have to think of your entire application as one service or component that has many working parts. I wouldn’t need the toe function for my arm if my arm would never use the toe. So why would I load all functions of my toe into my head file if I’m never going to use my toe until I’m walking with my feet :grinning: hope this helps.

Ryan.

Came across this topic after running into the same issue. It seems with SSR the server-side Template. [templateName].helpers block works inside a Meteor method. Hope that helps!