Questions tagged [pystache]

Pystache is a Python implementation of the Mustache templating language.

Pystache is a Python implementation of the Mustache templating language.

Mustache is a 'framework-agnostic, logic-free templating system'.

It is intentionally logic-free - there are no if statements, for-loops or functions.

It allows simple template substitution; for example

 Hello {{person.name}}.  Your age is {{person.age}}

Resources:

13 questions
21
votes
1 answer

Python dump json with accents

How can i print a json with special characters as "à" or "ç"? I can print like this: import json weird_dict ={"person": "ç", "á": 'à', "ç": 'ã'} print json.dumps(weird_dict, indent=4, sort_keys=True) output: { "person": "\u00e7", …
ePascoal
  • 2,362
  • 6
  • 26
  • 44
7
votes
2 answers

Pystache without escaping (unescaped)

I'm using pystache to render the templates. I'm getting & in the output when I render context variables having &. How can get rid of & where I need & . Same thing is happening with django templating as well >>> pystache.render('The URL…
neotam
  • 2,611
  • 1
  • 31
  • 53
4
votes
2 answers

How to render array of data into multiple mustache partials?

I'm using Python's pystache (which is the standard Mustache api). Here is an example of my data's structure: { "results": [ { "user": "foo", "flags": [ "a", "b", "c" ] }, { ... } ] } Now in…
Integralist
  • 5,899
  • 5
  • 25
  • 42
4
votes
2 answers

Iterating over keys and values of a dictionary in mustache / pystache

Suppose I have simple dictionary like this: d = {'k1':'v1', 'key2':'val2'} How can I render key, value lines in pystache using that dictionary?
LetMeSOThat4U
  • 6,470
  • 10
  • 53
  • 93
4
votes
1 answer

mustache/pystache: Rendering complex objects

I'm trying to wrap my head around rending complex objects using Mustache. I'm actually in Python using pystache, but the docs say it's compatible with the JS edition of Mustache. In mustache, all works nice if information were a simple string:…
101010
  • 14,866
  • 30
  • 95
  • 172
3
votes
3 answers

How can I render keys with '.' in Pystache?

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…
Tejas
  • 284
  • 2
  • 8
3
votes
3 answers

Understanding lambdas in pystache

Say I want to write a function that format floats with 2 digits in pystache. I want both the float number and the function in the context (I believe this is the correct philosophy of Mustache). What should I do? In order to make the problem clear, I…
luca.vercelli
  • 898
  • 7
  • 24
1
vote
1 answer

Deriving IP Range and Netmask using Cloudformation and Pystache

So, I've got an interesting one - Cloudformation allows the use of Mustache templates (via Pystache) to build configuration files via AWS::CloudFormation::Init (They bury this a few paragraphs down, but it's there). This is useful to me, as I need…
1
vote
1 answer

Pystache html characters replaced when using multiple files

I am using pystache (on Python 3.4) to template HTML files to be sent through email. I have a main.mustache file in which some of the tags are meant to be replaced by content of other .mustache files. So I have something like this (simplified…
1
vote
0 answers

mustache loop over dict of items without a name (by index)

heres my dict: { 1: { 'A': u'Eggs', 'B': 1400, 'C': u'Jibber', 'D': u'355'}, 2: { 'A': u'Avocados', 'B': 1000, 'C': u'Jabber', 'D': u'356'}, ..} Template.mustache {{#each}} …
codervince
  • 316
  • 4
  • 15
1
vote
1 answer

Where is documentation for pystache {{.}} ? (dot / period / implicit operator tag)

I am looking at some pystache template code that has this: {{#image_size}}width="{{.}}"{{/image_size}} It looks like {{.}} gets replaced by the value of image_size. Where is the pystache / mustache documentation that explains this? I looked…
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
0
votes
1 answer

insert several strings into xml at a marker

I would like to add a list of equations in a CSV to an xml doc for importing into moodle lms. Is there a way i can do this with python. along the lines of a mail merge. I have tried with libre office but the xml gets changed i have tried the…
0
votes
2 answers

pystache - return all templates in a string

In pystache (or most templating libraries), you can do a substitution such as this: >>> print pystache.render('{{person}} in {{place}}', {'person': 'Mom', 'place': 'Spain'}) Mom in Spain Is it possible to do the 'opposite'? i.e. return a dictionary…
smg
  • 1,133
  • 1
  • 11
  • 22