From 1ecb7b4b26aea75f01e242e1a86741868e1f6624 Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Tue, 1 Feb 2022 13:54:22 +0300 Subject: [PATCH] temlates_engine: support for nested templates including --- templates_engine.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/templates_engine.py b/templates_engine.py index 00957aa..7fd618a 100644 --- a/templates_engine.py +++ b/templates_engine.py @@ -15,10 +15,16 @@ def render(template_name: str, context: dict): template_path = join(templates_dir, template_name) template = get_file_content(template_path) - for include_statement in re.findall(include_pattern, template): - file_include = include_statement.split(' ')[1][1:] - include_content = get_file_content(join(templates_dir, file_include)) - template = template.replace(include_statement, include_content) + including = True + + while including: + including = False + + for include_statement in re.findall(include_pattern, template): + including = True + file_include = include_statement.split(' ')[1][1:] + include_content = get_file_content(join(templates_dir, file_include)) + template = template.replace(include_statement, include_content) for var_to_replace in re.findall(variable_pattern, template): key = var_to_replace.split(' ')[1]