Software:Genshi (templating language)

From HandWiki
Genshi
Developer(s)Edgewall Software
Initial releaseAugust 3, 2006; 17 years ago (2006-08-03)
Operating systemCross-platform
TypeTemplate Engine
License3-clause BSD license[1]
Websitegenshi.edgewall.org

Genshi is a template engine for XML-based vocabularies written in Python. Genshi is used to easily insert generated output into XML-based languages, usually HTML, and reuse elements between documents. Genshi's syntax is based on Kid, but its architecture is different. Genshi aims to implement some of its functionality while processing templates faster, by dynamically processing templates using a stream based API, instead of compiling templates to Python code.[2]

Genshi can be used with several Python web frameworks, such as CherryPy,[3][4] TurboGears,[5] Pylons[6] and web2py.[7] Genshi was the default templating language for TurboGears from versions 1.1[8] to 2.3.8.[9]

Genshi markup

Genshi makes use of namespaces to embed instructions into HTML. A typical instruction is given as an attribute, with a Python expression inside the quotes. For example, the following will render a paragraph that shows 4:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/">
    <body>
        <p py:content="2 + 2">This will be replaced with 4</p>
    </body>
</html>

Because of the use of namespaces, Genshi can be used in WYSIWYG HTML editors.[10][11]

Differences between Kid and Genshi

  • Genshi directly interprets templates (unlike Kid, which generates Python code)[12]
  • Genshi uses XInclude for template reuse[12]
  • Genshi adds attributes Kid does not have, like py:choose[12]
  • Genshi templates are easier to debug, because it tracks template source file names and line numbers, and errors from Genshi's interpreter produce more comprehensible stack traces than from Kid's generated code.[12]

References

  1. "License – Genshi". https://genshi.edgewall.org/wiki/License. 
  2. "What is Genshi?". http://genshi.edgewall.org/wiki/GenshiFaq#WhatisGenshi. Retrieved 2008-01-20. 
  3. "CherryPy – Genshi". http://genshi.edgewall.org/wiki/CherryPy. Retrieved 2009-09-26. 
  4. "Genshi - CherryPy Tools - Trac". Archived from the original on 2012-02-27. https://web.archive.org/web/20120227062117/http://tools.cherrypy.org/wiki/Genshi. Retrieved 2009-09-26. 
  5. "Genshi Templating". http://docs.turbogears.org/1.0/GenshiTemplating. Retrieved 2008-01-20. 
  6. "Genshi Templates - Pylons Cookbook". http://wiki.pylonshq.com/display/pylonscookbook/Genshi+templates. Retrieved 2008-01-20. 
  7. "web2py: Enterprise Web Framework". http://www.web2py.com/AlterEgo/default/show/162. Retrieved 2009-09-26. 
  8. Ramm, Mark. "TurboGears 1.1 and Beyond". http://compoundthinking.com/blog/index.php/2007/06/27/turbogears-11-and-beyond/. Retrieved 2008-01-20. 
  9. Molina, Alessandro. "Docs Review". https://groups.google.com/g/turbogears-trunk/c/sKt3S9m4Me8. Retrieved 2024-01-18. 
  10. "Choosing a templating language". Archived from the original on 2010-06-16. https://web.archive.org/web/20100616155159/http://docs.cherrypy.org/dev/progguide/choosingtemplate.html#id3. Retrieved 2010-05-30. 
  11. "Choosing a templating language". Archived from the original on 2008-01-17. https://web.archive.org/web/20080117034122/http://www.cherrypy.org/wiki/ChoosingATemplatingLanguage#Genshi. Retrieved 2008-01-20. 
  12. 12.0 12.1 12.2 12.3 "Comparing Genshi to Kid". http://genshi.edgewall.org/wiki/GenshiVsKid. Retrieved 2008-01-20. 

External links