Templates#
Developing a template#
Please see the Modules section on how to structure a module.
Having said that, this is the base file we are extending from.
1<!DOCTYPE html>
2<html>
3<head>
4 {% include 'base/blocks/resources.html'%}
5 {% include 'base/blocks/default_styles.html'%}
6 {% block pagehead %}{% endblock %}
7</head>
8<body class=" shopyo-main-area">
9 {% include "base/nav_base.html" %}
10 {% include 'base/blocks/flashed_messages.html'%}
11
12 <div class="container">
13
14 <br>
15 {% block content %}{% endblock %}
16 </div>
17</body>
18</html>
It includes:
space for user-supplied head (block pagehead)
space for user-supplied body (block body)
notification mechanism on the top right
If you extend the base template, you will be able to use the notification mechanism used for shopyo api
Global values for templates#
Global values for templates can be found in shopyoapi/enhance.py in this function
1def base_context():
2 """
3 Used to define global template values
4
5
6 Returns
7 -------
8 dict
9 copy of dictionary
10 """
11
12 base_context = {}
13 return base_context.copy()
Passing parameters to templates#
here is a demo on returning template vars:
#
# ...
@module_blueprint.route('/abc')
def somefunc():
context = {}
form = PageForm()
context.update({
'form':form,
'module_name': module_name
})
return render_template('page/dashboard.html', **context)
yo_render#
yo_render simplifies your life
from shopyo.api.templates import yo_render
...
@module_blueprint.route("/render_demo")
def render_demo():
context = {
'fruit': 'mango'
}
return yo_render('blogus/render_demo.html', context)