Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use Python on mustache template files
#2
Nested template fantastic solution.
First render stuff that you need insde master template, add it to dictionary and render master template.

Master template (diviera_master.txt):

<title>{{title}}</title>
{{content}}
Use {{{content}}} (triple mustache) if you want use HTML as a content.

Content template (diviera_content.txt):
This is {{name}}!

Python code:
import chevron

strings = {'title': 'Fantastic title',
            'name':'Sparta'}

#content
with open('diviera_content.txt', 'r') as cf:
    newContent = chevron.render(cf, strings)
    contentString = {'content' : newContent}
    strings.update(contentString)

#master
with open('diviera_master.txt', 'r') as f:
    fillup = chevron.render(f, strings)
    print(fillup)


#result
with open('diviera_final.txt', 'w') as nf:
    nf.write(fillup)
Messages In This Thread
Use Python on mustache template files - by Janusz - 12-17-2020, 11:28 AM
RE: Use Python on mustache template files - by Janusz - 12-17-2020, 02:08 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)