fix: Render web blocks using web_template.render
- web_block object need not be a WebPageBlock instance
This commit is contained in:
parent
627aff4bb8
commit
8f0f17eb7e
4 changed files with 13 additions and 6 deletions
|
|
@ -7,15 +7,19 @@
|
|||
web_block.css_class
|
||||
]) -%}
|
||||
|
||||
{%- if web_template.type == 'Section' -%}
|
||||
{%- if not web_block.hide_block -%}
|
||||
<section class="section {{ classes }}" data-section-idx="{{ web_block.idx | e }}"
|
||||
data-section-template="{{ web_block.web_template | e }}">
|
||||
{%- if web_block.add_container -%}
|
||||
<div class="container">
|
||||
{%- endif -%}
|
||||
{{ web_block.render() }}
|
||||
{{ web_template.render(web_block.web_template_values) }}
|
||||
{%- if web_block.add_container -%}
|
||||
</div>
|
||||
{%- endif -%}
|
||||
</section>
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{{ web_template.render(web_block.web_template_values) }}
|
||||
{%- endif -%}
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ def web_block(template, values, **kwargs):
|
|||
|
||||
|
||||
def web_blocks(blocks):
|
||||
from frappe import get_doc, throw
|
||||
from frappe import throw, _dict
|
||||
from frappe.website.doctype.web_page.web_page import get_web_blocks_html
|
||||
|
||||
web_blocks = []
|
||||
|
|
@ -208,7 +208,7 @@ def web_blocks(blocks):
|
|||
if not block.get('template'):
|
||||
throw('Web Template is not specified')
|
||||
|
||||
doc = {
|
||||
doc = _dict({
|
||||
'doctype': 'Web Page Block',
|
||||
'web_template': block['template'],
|
||||
'web_template_values': block.get('values', {}),
|
||||
|
|
@ -217,9 +217,9 @@ def web_blocks(blocks):
|
|||
'add_container': 1,
|
||||
'hide_block': 0,
|
||||
'css_class': ''
|
||||
}
|
||||
})
|
||||
doc.update(block)
|
||||
web_blocks.append(get_doc(doc))
|
||||
web_blocks.append(doc)
|
||||
|
||||
out = get_web_blocks_html(web_blocks)
|
||||
|
||||
|
|
|
|||
|
|
@ -208,8 +208,9 @@ def get_web_blocks_html(blocks):
|
|||
extracted_scripts = []
|
||||
extracted_styles = []
|
||||
for block in blocks:
|
||||
web_template = frappe.get_cached_doc('Web Template', block.web_template)
|
||||
rendered_html = frappe.render_template('templates/includes/web_block.html',
|
||||
context={'web_block': block})
|
||||
context={'web_block': block, 'web_template': web_template})
|
||||
html, scripts, styles = extract_script_and_style_tags(rendered_html)
|
||||
out.html += html
|
||||
if block.web_template not in extracted_scripts:
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ class WebTemplate(Document):
|
|||
open(path, "w").close()
|
||||
|
||||
def render(self, values):
|
||||
values = values or '{}'
|
||||
values = frappe.parse_json(values)
|
||||
return get_rendered_template(self.name, values)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue