dust

11
Introduction To Dust

Upload: shashi-bhushan

Post on 26-Jan-2017

79 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Dust

Introduction ToDust

Page 2: Dust

What is DUST

Page 3: Dust

▪ Dust is a Javascript templating engine

▪ Designed to run asynchronously on both the server and the browser

▪ Not truly Logic Less▪ Dust works where Javascript

works

Page 4: Dust

Advantages

– Template is compiled to Javascript– Available on client side, so faster rendering and less network

load– Dust can precompile your templates , or dynamically load them– Dust works where Javascript works, No other dependencies

Page 5: Dust

Example

// TemplateHello {name}! You have {count} new messages.

// Data {"name": "Mick","count": 30}

// ResultHello Mick! You Have 30 new messages.

Page 6: Dust

Section and context

– A simple key reference will look first in the current context and, if not found, search all higher levels up to the root looking for the name– It will not search downward– {#A}{anotherName}{/A} outputs "rootName"

Page 7: Dust

Paths

– If we want to work only with the data within a specific context, we can use dotted notation (called paths) to define the context– {A.B.name} will output "Bob"– Path notation allows you to reference a path outside a current

context

Page 8: Dust

Paths // Template {#A.B}

Name in B = {name}, Name in A = {A.name}{/A.B}

// Data { "name": "root", "anotherName": "root2", "A":{ "name":"Albert", "B":{ "name":"Bob" } } } //Result Name in B = Bob, name in A = Albert

Page 9: Dust

Explicit Context Setting

// Template {#A:A2}

{#names} {.} - {type}

{/names} {/A}

// Data {

"A": { names :

["Albert", "Alan"] }, "A2":{ "type":"Student" } }

Page 10: Dust

Passing Parameters

{#A.B foo=A.name bar=anotherName myName="shashi"}

{foo} {name} {bar} {me} {/A.B}

Page 11: Dust

References

http://www.dustjs.com/https://github.com/linkedin/dustjs