These are chat archives for ractivejs/ractive

28th
Jul 2015
Noel Quiles
@EnMod
Jul 28 2015 01:08

Would anyone know how to make a dynamic template that changes depending on whether or not the incoming data is an array? I'm making a dossier sorter for Castlevania characters as a way to practice using Ractive, and my data has some fields being single values for some heroes, and arrays for other heroes.

Trying to code this with an #if template and the returned value of a checking expression have been a no-go.

Arye Shalev
@pantchox
Jul 28 2015 07:06
@EnMod i suggest you to make a quick fiddle explaning your purpose. i am no expert in ractive but with examples i might get an idea
Martin Kolárik
@MartinKolarik
Jul 28 2015 17:48
@EnMod something like this?
{{#if Array.isArray(value)}}
    {{>arrayTemplate}}
{{else}}
    {{>singleValueTemplate}}
{{/if}}
Guilherme Aiolfi
@guilhermeaiolfi
Jul 28 2015 19:03
value.length > 0, I think would work too
But Martin suggestion is better
Martin Kolárik
@MartinKolarik
Jul 28 2015 19:07
@guilhermeaiolfi if "single value" is a string, it has length as well
Guilherme Aiolfi
@guilhermeaiolfi
Jul 28 2015 19:08
True