{{user.username}} follows you.
{{/if}} HTML and template tags are mixed. Here we use double mustaches to read values from the model. An if-statement (not actual syntax!) is used to conditionally render the paragraph: only if the user we’re looking at is following us.Arran follows you
If Arran is following us the paragraph renders.{{username}}
{{component FollowButton}} {{/with}} Here’s an example. Within the context of a particular user model we render the FollowButton component. It has a view defined elsewhere that is rendered in the DOM tree where the component is declared.{{username}}
{{behavior UserRelationship}} {{if followed by us}} Stop following {{else}} Follow {{/if}} {{/behavior}} {{/with}} In this example we directly apply behavior from a separate JavaScript file to a view. In this case the UserRelationship behavior, with an event hooked up to the button to toggle the following state. Assuming the underlying user model is updated to reflect the current relationship, the button text will automatically change.{{username}}
{{behavior UserRelationship}} {{if followed by us}} Stop following {{else}} Follow {{/if}} {{/behavior}} {{/with}} In this example we directly apply behavior from a separate JavaScript file to a view. In this case the UserRelationship behavior, with an event hooked up to the button to toggle the following state. Assuming the underlying user model is updated to reflect the current relationship, the button text will automatically change.Arran
Follow CLICK! Let's click on that button…Arran
Stop following Behind the scenes the behavior changes the following state. The model also gets updated, which means the if-statement changes. And presto! The button now says “Stop following”.Arran
Follow CLICK! Let's click on that button…Arran
Follow Behind the scenes the behavior changes its "updating" state. The button gets disabled.Arran
Stop following When the model has been changed the button is re-enabled and the text has changed to “Stop following”.{{username}}
! ! {{if we’re not on the server…}} {{behavior UserRelationship}} ! ! ! ! … ! {{/behavior}} ! ! {{/if}} {{/with}} We should only render the follow button if the view isn’t being rendered on the server. This would be because the button requires JavaScript to function, and we can’t guarantee that the users who see the server output have JavaScript enabled.