0

I have an array like this:

array = [0, 1, 2, 3, 4, 5, 6, 7]

And 2 configuration variables:

var start = 2;
var count = 3;

And I want mustache to render the array exactly as the configuration demands to. My template is like this:

{#array}
    <p>{.}</p>
{/array}

I want my output to be this one:

<p>2</p>
<p>3</p>
<p>4</p>

How can I achieve that?

1 Answer 1

1

In your javascript you need to build subset of data using your start and count. For this you can use a library like underscore.js as shown below:

var array =  [0, 1, 2, 3, 4, 5, 6, 7];
var start = 2,  count=3;
var subset = _.range(start, start+count);

Then your Mustache template can be passed with the subset variable. You need to keep your Mustache templates as simple as possible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.