Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| richclient:emberjs:templates [2018/01/19 02:29] – [Itération sur une liste d'éléments <nowiki>{#each}</nowiki>] jcheron | richclient:emberjs:templates [2019/08/31 14:21] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 26: | Ligne 26: | ||
| Les blocks expressions commencent par **< | Les blocks expressions commencent par **< | ||
| - | ==== Itération sur une liste d' | + | ==== Itération sur une liste d' |
| <sxh html> | <sxh html> | ||
| Ligne 36: | Ligne 36: | ||
| </ | </ | ||
| + | === Itération avec utilisation de l' | ||
| + | |||
| + | <sxh html> | ||
| + | <ul> | ||
| + | {{#each people as |person index|}} | ||
| + | < | ||
| + | {{/each}} | ||
| + | </ul> | ||
| + | </ | ||
| + | |||
| + | === Itération avec une éventuelle liste vide === | ||
| + | |||
| + | <sxh html> | ||
| + | {{#each people as |person|}} | ||
| + | Hello, {{person.name}}! | ||
| + | {{else}} | ||
| + | Sorry, nobody is here. | ||
| + | {{/each}} | ||
| + | </ | ||
| + | |||
| + | ==== Conditions {{#if}} ==== | ||
| + | |||
| + | === Condition sur une seule ligne === | ||
| + | |||
| + | <sxh html> | ||
| + | <div> | ||
| + | {{if isFast " | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | === Condition multi-lignes === | ||
| + | |||
| + | <sxh html> | ||
| + | {{#if person}} | ||
| + | Welcome back, < | ||
| + | {{/if}} | ||
| + | </ | ||
| + | |||
| + | === else === | ||
| + | <sxh html> | ||
| + | {{#if person}} | ||
| + | Welcome back, < | ||
| + | {{else}} | ||
| + | Please log in. | ||
| + | {{/if}} | ||
| + | </ | ||
| + | |||
| + | === elseif === | ||
| + | <sxh html> | ||
| + | {{#if isAtWork}} | ||
| + | Ship that code! | ||
| + | {{else if isReading}} | ||
| + | You can finish War and Peace eventually... | ||
| + | {{/if}} | ||
| + | </ | ||
| + | |||
| + | === unless === | ||
| + | unless est la négation du if (if not) | ||
| + | <sxh html> | ||
| + | {{#unless hasPaid}} | ||
| + | You owe: ${{total}} | ||
| + | {{/unless}} | ||
| + | </ | ||
| + | |||
| + | ==== liens {{link-to}} ==== | ||
| + | link-to permet de générer des liens href et prend 1 ou 2 arguments : | ||
| + | * le premier est le nom d'une route | ||
| + | * le second (facultatif) correspond à l'id d'un model pour les segments dynamiques | ||
| + | |||
| + | Avec la route déclarée dans router.js suivante : | ||
| + | <sxh javascript; | ||
| + | Router.map(function() { | ||
| + | this.route(' | ||
| + | this.route(' | ||
| + | }); | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | et le fichier de template : | ||
| + | <sxh html; | ||
| + | <ul> | ||
| + | {{#each photos as |photo|}} | ||
| + | < | ||
| + | {{/each}} | ||
| + | </ul> | ||
| + | </ | ||
| + | |||
| + | Ember génère le html : | ||
| + | |||
| + | <sxh html> | ||
| + | <ul> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ul> | ||
| + | </ | ||
| + | |||
| + | === Liens inline === | ||
| + | |||
| + | <sxh html> | ||
| + | A link in {{#link-to " | ||
| + | and a link in {{link-to " | ||
| + | </ | ||
| + | |||
| + | Génère le code html suivant : | ||
| + | <sxh html> | ||
| + | A link in <a href="/"> | ||
| + | and a link in <a href="/"> | ||
| + | </ | ||