<<TableOfContents(2)>>
## page was renamed from Jinja2
= Jinja2 =
Jinja2 is a modern and designer friendly templating language for Python, modelled after Django’s templates.
 * https://palletsprojects.com/p/jinja/
 * https://jinja.palletsprojects.com/en/2.10.x/

== Slackware 14 installation ==
 * wget https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.1.tar.gz
 * cp Jinja2-2.7.1.tar.gz /tmp
 * tar xvzf Jinja2-2.7.1.tar.gz
 * cd Jinja2-2.7.1
 * python setup.py build
 * python setup.py install

== Check installation ==
{{{#!highlight python
python
Python 2.7.3 (default, Jul  3 2012, 21:16:07) 
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import jinja2
>>> jinja2.__version__
'2.7.1'
>>> quit()
}}}

== Jinja2 test ==
Check [[Python/CherryPy]]

 * mkdir -p /var/www/htdocs/jinja2test/templates
 * cd /var/www/htdocs/jinja2test

File '''/var/www/htdocs/jinja2test/jinja2test.wsgi'''
{{{#!highlight python
import sys
sys.stdout = sys.stderr
import cherrypy

from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('/var/www/htdocs/jinja2test/templates'))

cherrypy.config.update({'environment': 'embedded'})

class Jinja2Test(object):
    @cherrypy.expose
    def index(self):
        return "Hello World Jinja2Test!!!!"
    @cherrypy.expose
    def add(self,param1,param2):
       return str( int(param1)+int(param2) )
    @cherrypy.expose
    def testpage(self):
        t = env.get_template('test.html')
        navItems=[]
        for i in range(1,10):
                navItems.append( {'href':'hrefx','caption':'cap %d'%(i) } )
        return t.render( titlex="Titleeeee" , navigation=navItems )

jjtest = Jinja2Test()
application = cherrypy.Application(jjtest, script_name=None, config=None)
}}}

File '''/var/www/htdocs/jinja2test/templates/test.html'''
{{{#!highlight html
<html>
    <head></head>
    <body>
        <ul id="navigation">
        {% if navigation|count > 0 %}
        {% for item in navigation %}
        <li>
          <a href="{{item.href}}">{{item.caption}}</a> 
        </li>
        {% endfor %}
        {% endif %}
        </ul>
        <h1>My webpage {{titlex}} </h1>
    </body>
</html>
}}}

Add virtual host in '''/etc/httpd/vhosts.conf'''
{{{
<VirtualHost *:80>
    ServerName localhostjinja2test
    DocumentRoot "/var/www/htdocs/jinja2test"
    WSGIScriptAlias / /var/www/htdocs/jinja2test/jinja2test.wsgi
    <Directory "/var/www/htdocs/jinja2test">
      Require local
    </Directory>
</VirtualHost>
}}}

Add host to '''/etc/hosts'''
{{{
127.0.0.1 localhostjinja2test
}}}

Restart apache
 * /etc/rc.d/rc.httpd restart

Open URLs:
 * http://localhostjinja2test/
 * http://localhostjinja2test/add/3/4
 * http://localhostjinja2test/testpage