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.

Example template

{% extends "shopyo_base/main_base.html" %}
{% block content %}
<h1>Hello</h1>
{% endblock %}

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)