meteorhacks / meteor-ssr

Server Side Rendering for Meteor
https://atmospherejs.com/meteorhacks/ssr
264 stars 29 forks source link

Is there Child / Sub Templates Support? {{> myOtherTpl}} #51

Open zeroasterisk opened 7 years ago

zeroasterisk commented 7 years ago

Is there Child / Sub Templates Support? {{> myOtherTpl}}

How do I set that up?

Data-Meister commented 7 years ago

This should work as you've written it. If not you can use a dynamic template.

However see this issue #52 - you must explicitly specify data context for dynamic templates. Perhaps you also need to explicitly specify data context for sub templates too.

thebarty commented 7 years ago

@zeroasterisk: Can you share which solution you have used? I'd love to have some infos on this 👍

po-jo commented 7 years ago

hi @zeroasterisk: same as @thebarty, It would be cool to know how you solve this stuff (have the same, tried with data context with no result :( ) Thanks !

po-jo commented 7 years ago

It was a typo, {{> childTemplate}} inclusion works (don't forget to do a SSR.compileTemplate('chilTemplate', Assets.getText('childTemplate.html')) before). Sorry for the noise !

vany0114 commented 7 years ago

Hi @po-jo, Can you give me a little example, please?...it doesn't work for me. I have a child template inside the main template.

Server code:

SSR.compileTemplate('basicData', Assets.getText('contract/basicData.html'));
SSR.compileTemplate('main', Assets.getText('contract/main.html'));

var html_string = SSR.render('main', {
   css: css,
   contract: contract
});

Template code:

{{{getDocType}}}
<html>
<head>
    <meta charset="utf-8">
    <title>MVMCo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <style type="text/css">
        {{css}}
    </style>
</head>
<body class="body-contract-report">
    <h1>{{ contract.code }}</h1>

    {{> basicData contract=contract }}
</body>
</html>

So I just render the "main" template and I expected that its child renders too, but it doesn't happen, only rendered the main template content.

vany0114 commented 7 years ago

Forget it man, it was because I had the "template" tag into the child template, but in the server templates it doesn't necessary.