pystache icon indicating copy to clipboard operation
pystache copied to clipboard

Adding the ability to select list items in the context by index.

Open mintchaos opened this issue 12 years ago • 12 comments

This matches the behavior of JS implementations of mustache. Tested against mustache.js and Hogan.

>>> context = {"data": ['one', 'two', 'three']}
>>> pystache.render("{{ data.0 }}", context)
'one'

Tests added and all previous behavior maintained.

mintchaos avatar Feb 26 '13 23:02 mintchaos

Is this a duplicate of issue #134?

cjerdonek avatar Mar 17 '13 23:03 cjerdonek

@cjerdonek I haven't actually tried the syntax in #134, but I'd imagine that this solves that as well.

mintchaos avatar Mar 18 '13 05:03 mintchaos

I think checkin 316c9d4 to support element cherrypick by index with syntax "{{array_key.index}}" is very important feature for this project.

Without this feature, some data could not be rendered from array.

If you try http://mustache.github.io/#demo, you could find that javascript library has already supported this syntax.

godsarmy avatar Apr 26 '14 03:04 godsarmy

This has not been added yet?

gaastonsr avatar Apr 30 '15 18:04 gaastonsr

:+1:

Very important and interesting feature indeed!

denisvm avatar Jul 24 '15 01:07 denisvm

I would like to have this functionality as well.

grayb avatar Jan 14 '16 16:01 grayb

Hi @cjerdonek can this be merged please?

amrelhady avatar May 10 '16 10:05 amrelhady

I too would love to have this merged in. Any chance that this project will be updated ever again?

JiBB avatar Aug 04 '16 20:08 JiBB

Any reason why this hasn't been merged?

llama avatar Nov 08 '16 22:11 llama

@cjerdonek is this repo (and this useful PR that it contains) no longer being maintained?

jeremyjliu avatar Jul 21 '17 14:07 jeremyjliu

I would like this feature as well.

jeortizquan avatar Oct 09 '19 09:10 jeortizquan

but also would be nice to access the last element as a function

>>> context = {"data": ['one', 'two', 'three']}
>>> pystache.render("{{ data.first() }}", context)
'one'
>>> pystache.render("{{ data.last() }}", context)
'three'

jeortizquan avatar Oct 09 '19 10:10 jeortizquan