Fundamentals - Cheat Sheet II

Templating Basics:

Requiring Resources
<template>
        <require from='nav-bar'></require>
  
        <nav-bar router.bind="router"></nav-bar>

        <div class="page-host">
                 <router-view></router-view>
       </div>
</template>
When the browser loads in the template it very helpfully validates the structure of the HTML, notices that you have an invalid tag inside your table definition, and very unhelpfully removes it for you before Aurelia even has a chance to examine your template.
as-element attribute ensures a valid HTML table structure at load time

Compose an existing object instance with a view
<template>
        <table>
               <tr repeat.for="r of ['A','B','A','B']" as-element="compose" view='./template_${r}.html'>
        </table>
<template>

embedded template for above e.g.

template_A.html
<template>
      <td>I'm an A Row</td><td>Col 2A</td><td>Col 3A</td>
</template>

template_B.html
<template>
        <td>I'm an B Row</td><td>Col 2B</td><td>Col 3B</td>
</template>

containerless attribute - strips the container after the browser has loaded the DOM elements, & as such this method cannot be used to transform non-HTML compliant structures into compliant ones!

Illegal Table Code
<template>
        <table>
               <template repeat.for="customer of customers">
                       <tr>
                           <td>${customer.fullName}</td>
                       </tr>
              </template>
         </table>
</template>
Correct Table Code
<template>
        <table>
               <tr repeat.for="customer of customers">
                     <td>${customer.fullName}</td>
               </tr>
        </table>
</template>
Illegal Select Code
<template>
        <select>
               <template repeat.for="customer of customers">
                       <option>...</option>
               </template>
        </select>
</template>
Correct Select Code
<template>
        <select>
               <option repeat.for="customer of customers">...</option>
        </select>
</template>

Comments

Popular posts from this blog

Fundamentals - App Config & Startup - VIII

Fundamentals - Dependency Injection V

Style vs Css attribute