Skip to content

multi-template file and renderResponse support #40

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

multi-template file and renderResponse support #40

wants to merge 1 commit into from

Conversation

vivekvrao
Copy link

Added a couple of function to simplify using the module.

  1. multiple templates can be loaded from one file using loadTemplates
SSR.loadTemplates(Assets.getText('templates.html') );

<!-- file: private/templates.html -->
<template name="mytemplate">
      Hello {{username}}, <br>
      Now time is: {{time}}
</template>
<template name="another">...</template>
  1. Utility function for serving pages - renders the template with given data - and serves over http response with support for Head sections and metadata
SSR.renderResponse( templateName, data, responseStream, metadata) 

Router.route('/hello', function(){
    SSR.renderResponse( "mytemplate", { username: "me", time: "now" }, this.response, {title: "mypage", keywords:"test,ssr" } );
});

instead of compiling each template separately - added support to create single file using function 

SSR.loadTemplates(Assets.getText('templates.html') );

<!-- file: private/templates.html -->
<template name="mytemplate">
Hello {{username}}, <br>
Now time is: {{time}}
</template>
<template name="another">...</template>

SSR.renderResponse( templateName, data, responseStream, metadata) 
- renders the template with given data - and serves over http response with support for Head sections and metadata

e.g. 
Router.route('/hello', function(){
    SSR.renderResponse( "mytemplate", { username: "me", time: "now" }, this.response, {title: "mypage", keywords:"test,ssr" } );
});
@thebarty
Copy link

thebarty commented Dec 19, 2016

Hi there, does this mod allow use to do sub-template inclusion, like {{>subtemplate parameter="param1"}}?

SSR.loadTemplates(Assets.getText('templates.html') );

<!-- file: private/templates.html -->
<template name="mytemplate">
      Hello {{username}}, <br>
      Now time is: {{time}}
      {{>subtemplate parameter="param1"}}
</template>

<template name="subtemplate">
</template>

We could use this in lookback:meteor-emails lookback/meteor-emails#88

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants