iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 413 forks source link

How to use '{{> yield}}' and to display the right template #1559

Closed JeromeVi closed 7 years ago

JeromeVi commented 7 years ago

I'm trying to add iron router to my website and the problem I got is

my template calling {{> templateName }} no longer works

I join the code of body.html where I call mostly all my templates. I've read that I should use {{> yield}} but I don't understand how it will display the right template and what I need to do to re-use my templates...

lib/router.js

    Router.route('/', function () {
      this.render('acc');
    });

imports/ui/body.html

   <template name="acc">
    <body id="pageAcc">
      <div class="container">
        <header>
    <h3 id="titreRecherche">Rechercher un article </h3>
          <form id="tfnewsearch">
           <input type="text" class="tftextinput" id="tftextinput" size="35" maxlength="120"><input type="button" value="search" class="tfbutton">
          </form>
          {{#if currentUser}}
          <div id="whereAmi">
            <span title="En cliquant sur ce bouton vous accepter d'ajouter votre localisation dans les informations de l'article"><button type="submit" class="posBut">Me localiser</button></span>
          </div>
          <div id="mesArticles">
              <button type="button" id="showMesArticles">Afficher mes articles</button>
          </div>
          {{/if}}
          {{#if wantLoc}}
          <div id="instagramFeed">
              <button type="button" id="goToInstagramFeed">Afficher les photos de v__jerome</button>
          </div>
          {{/if}}
          <div id="connexion">
            <button type="submit" id="loginLink">{{> loginButtons}}</button>
          {{#if currentUser}}
          {{#if wantLoc}}
            <p>Vous êtes à: {{where}}</p>
          {{/if}}
          {{/if}}
          </div>
          {{#if currentUser}}
              {{> ajoutement}}
          {{/if}}
        </header>

          {{#if wantInsta}}
          <div id="IF">
            <h1 id="titreInsta">Les photos de v__jerome</h1>
              {{> instagramfeed}}
          </div>
          {{/if}}
        <h1 id="titreListe">Les articles</h1>
        <ul id="lesArticles">
          {{#each articles}}
            {{> article}}
          {{/each}}
        </ul>
    {{#if wantModif}}
      {{> modify}}
    {{/if}}
    {{#if currentUser}}
    {{#if wantLoc}}
    <div id ="map"></div>
    <script async defer
      src="https://maps.googleapis.com/maps/api/js?key=myKey&callback=initMap">
      </script>
    {{/if}}
    {{/if}}
      </div>
     <a href="#" class="scrollup">Back to top</a>
     <input type="hidden" id="nextArt">
    </body>
    </template>

imports/ui/body.js

 import { Session } from 'meteor/session'
    import { Template } from 'meteor/templating';

    import { Articles } from '../api/articles.js';
    import './article.js';
    import './body.html';

    import './ajoutement.html';
    import './modify.html';
    import './instagramFeed.html';

    Template.body.onCreated(function bodyOnCreated() {
      Meteor.subscribe('articles');
      Session.set('insta',1);
      Session.set('showArt',1);
    });

    Template.body.helpers({
      articles() {
        return Articles.find({}, {sort: {createdAt: -1}});
      },
      wantModif: function() {
        return Session.get('wantModif');
      },

      [then a lot of Template.body.helpers ]

And that's all I did. Can someone help me to use my templates again ?

romain-neil commented 7 years ago

Is not iron router, it's blaze. on the file "imports/ui/body.html", the name of the template is acc, not templateName. {{> acc}}