From f011688df8b53ea2a1085fcb467b6f3cd8789a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 11 Jul 2024 15:09:09 +0200 Subject: [PATCH] Change the example with user to an example with different products --- EXAMPLES.md | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index 9c0e525..6a12a8a 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -50,45 +50,52 @@ In `base.html`, we can include a navbar which depends of each page language by : For all pages, if the page contains the metadata `lang` then the block will be searched as `blocks//navbar.html`, and will be `blocks/en/navbar.html` if not found.\ Else, the `default("")` filter allow to overpass the error and the block will be searched as `blocks/navbar.html`, and will be `blocks/en/navbar.html` if not found.\ -## With user levels as version : -For this example, we have a widget that prints information about user in `jinja2/widgets/profile.html` : +## With a product as version : +For this example, we have a widget that prints information about a product in `jinja2/widgets/product.html` : ```jinja -{% macro profile( - USER_TYPE = "guest", +{% macro product( + PRODUCT = {"name": "", "description": "", "price":""}, ) %}
-

{{ USER_TYPE }} profile

- {% if user_type == 'admin' %} -

Status : Administrator

- {% else %} -

Status : Guest user

- {% endif %} +

{{ PODUCT.name }}

+

{{ PRODUCT.description }}

+

Buy it for {{ PRODUCT.price }}$ !

{% endmacro %} ``` -With two version of blocks `jinja2/blocks/admin/profile.html` and `jinja2/blocks/guest/profile.html` : +With two version of blocks `jinja2/blocks/prod1/product.html` and `jinja2/blocks/prod2/product.html` : ```jinja -{% from "widgets/profile.html" import profile %} - -{{ profile(USER_TYPE = "admin") }} +{% from "widgets/product.html" import product %} +{{ product( + PRODUCT = + { + "name": "product1" + "description": "..." + "price": "12" + } +) }} ``` ```jinja -{% from "widgets/profile.html" import profile %} - -{{ profile() }} +{% from "widgets/product.html" import product %} +{{ product( + PRODUCT = + { + "name": "product2" + "description": "..." + "price": "36" + } +) }} ``` And finally we can use this blocks with : ```jinja {% from "blocks/block.html" import block %} - {{ block( - NAME = "profile" - VERSION = "admin" + NAME = "product" + VERSION = "prod1" )}} - {{ block( - NAME = "profile" - VERSION = "guest" + NAME = "product" + VERSION = "prod2" )}} ```