Question

I've the following page:

main.html

<html>
<body>
   <div>
      [more static content]
      <div id="content"></div>
   </div>
</body>
</html>

tpl1.html

<template name="something">
   [...]
</template>

And I want to use Iron-router to fill the "something" template into the "content" div. I cannot find a way to route a path to render only a div. I tried to do something like:

<div id="content">{{yield}}</div>

but always the result is:

<html>
<body>
   <div>
      [more static content]
      <div id="content"></div>
   </div>
   [... content from "something" template ...]
</body>
</html>

And not:

<html>
<body>
   <div>
      [more static content]
      <div id="content">[... content from "something" template ...]</div>
   </div>
</body>
</html>

what is what I want to do.

My iron-router config is:

Router.map(function () {
    this.route('principal',{
        path:"/someaction",
        template:"something"
    });

¿How can I do that? Thanks!

Was it helpful?

Solution

You basically have it. The only additional code you should need is adding a {{yield}} into your div:

<html>
<body>
   <div>
      [more static content]
      <div id="content">{{yield}}</div>
   </div>
</body>
</html>

If you just read down the iron-router github a bit you should quickly find a great section talking about yield. You can even use multiple ones.

OTHER TIPS

The problem was solved, putting the main.html text into a template:

<template name="main">
   <html>
   <body>
     <div>
         [more static content]
         <div id="content">{{yield}}</div>
      </div>
   </body>
   </html>
</template>

and in the router:

 this.route('principal',{
    path:"/someaction",
    template:"something",
    layoutTemplate:"main"
 });

This isn't what I want (because now the accounts-ui doesn't work), but it's something :P.

If someone knows how to do the original task, it will be excelent!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top