Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle switch cases in Meteor templates
    primarykey
    data
    text
    <p>What's the best way to handle a switch case in a template (eg: a button with 4 possible states)? It seems wrong to pull the html out into a helper, but it feels just as bad to put the logic into the template...</p> <p><strong>Edit:</strong></p> <p>As you can see, putting the html in a helper is far from ideal, but changing a class, a tag-name, properties, and content, would make the template wholly unreadable.</p> <pre><code>Template.nextMeetup.helpers({ rsvpButton: function(rsvp) { var button; switch(rsvp){ case 'yes': button = '&lt;a ' + this.event_url + 'class="rsvp btn btn-success pull-right" title="visit event page" target="_blank"&gt;&lt;i class="icon-check"&gt;&lt;/i&gt; I\'m Attending&lt;/a&gt;'; break; case 'maybe': button = '&lt;a ' + this.event_url + 'class="rsvp btn btn-warning pull-right" title="visit event page" target="_blank"&gt;&lt;i class="icon-warning-sign"&gt;&lt;/i&gt; I might go&lt;/a&gt;'; break; case 'no': button = '&lt;a ' + this.event_url + 'class="rsvp btn btn-danger pull-right" title="visit event page" target="_blank"&gt;&lt;i class="icon-remove"&gt;&lt;/i&gt; I\'m not going&lt;/a&gt;'; break; case 'none': button = '&lt;a ' + this.event_url + 'class="rsvp btn btn-inverse pull-right" title="visit event page" target="_blank"&gt;&lt;i class="icon-spinner"&gt;&lt;/i&gt; I havn\'t decided&lt;/a&gt;'; break; default: button = '&lt;button class="rsvp signIn btn btn-disabled pull-right"&gt;Sign in to RSVP&lt;/button&gt;'; } return new Handlebars.SafeString(button); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload