Platform
Resources
Pricing
Sign in
Get started
Fabian Iwand
Web developer and autodidact with an interest in creative coding.
Workspace
Fork
Published
Hello, ... !
By
Fabian Iwand
Edited
Jun 9, 2019
4 stars
Insert cell
Insert cell
Insert cell
Handlebars
=
{
const
hb
=
await
require
(
'handlebars@4.1.2/dist/handlebars.min.js'
)
;
// Register a helper.
// n is the argument, block the inner content.
hb
.
registerHelper
(
'times'
,
(
n
,
block
)
=>
{
let
s
=
''
,
i
=
n
;
while
(
i
--
>
0
)
s
+=
block
.
fn
(
i
)
;
return
s
;
}
)
;
return
hb
;
}
Insert cell
Insert cell
table_hbs
=
Handlebars
.
compile
(
`
<table>
{{#if headers}}
<thead>
<tr>{{#each headers}}<th>{{@this}}</th>{{/each}}</tr>
</thead>
{{/if}}
<tbody>
{{#each rows}}
<tr>{{#each @this}}<td>{{{@this}}}</td>{{/each}}</tr>
{{/each}}
</tbody>
</table>
`
)
Insert cell
Insert cell
choochoo_hbs
=
Handlebars
.
compile
(
`
🚂{{#times size}}🚃{{/times}}{{#if late ~}}
{{#times late ~}} {{/times}}🏃
{{/if}}
`
)
Insert cell
Insert cell
md
`
### Departures
${
table_hbs
(
{
headers
:
[
'Train'
,
'Status'
]
,
rows
:
[
[
'Train 1'
,
choochoo_hbs
(
{
size
:
5
}
)
]
,
[
'<span style=color:red>Train 2</span>'
,
choochoo_hbs
(
{
size
:
3
,
late
:
55
}
)
]
,
[
'Train 3'
,
choochoo_hbs
(
{
size
:
8
}
)
]
,
]
}
)
}
`
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Handlebars
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
table_hbs
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
choochoo_hbs
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML