3

I have dict that has . in the key names. I looked at the code for pystache and couldn't find anything I can use to substitute . with something else.

Seems like there is an option to replace delimiters but nothing for ..

Example:

>>> from pystache import Renderer
>>> renderer = Renderer()
>>> renderer.render("{{user.first.name}}", {"user": {"first.name": "xyz"}})
u''
>>> renderer.render("{{user.first.name}}", {"user": {"first": {"name": 
"xyz"}}})
u'xyz'
>>>

Is there any way I could use a different "delimiter" for traversing dicts?

Tejas
  • 284
  • 2
  • 8

3 Answers3

0

Seems like there is no way to get around it.

https://github.com/defunkt/pystache/issues/141

Tejas
  • 284
  • 2
  • 8
0

Set Delimiter tags start with an equal sign and change the tag delimiters from {{ and }} to custom strings.

Consider the following contrived example:

  • {{default_tags}} --> {{=@$ $@=}}

  • @$ erb_style_tags $@ --> @$={{ }}=$@

  • {{ default_tags_again }}

Here we have a list with three items. The first item uses the default tag style, the second uses erb style as defined by the Set Delimiter tag, and the third returns to the default style after yet another Set Delimiter declaration.

but mustache is a logic less syntax, if a '.' is placed inside the mustache delimiters then it will first search for the string before the dot first, if it is not found, it will return null.

In your first case it has searched for user which is found and then searched for first (not first.name) which is not found and has returned null.

0

I hope I'm not too late with my answer(original question was asked in 2018.). :-)

But here how I achieved desired output:

>>> import pystache

>>> pystache.render("--->{{ user.first.name }}<---", user={"first": {"name": "xyz"}})

'--->xyz<---'

Library version: pystache==0.6.0

Vadim Zabolotniy
  • 347
  • 5
  • 16