misc: add option for placeholders to create an outer tag (#62415)
This commit is contained in:
parent
9da25d0f8c
commit
b02b7b0e5b
|
@ -136,7 +136,15 @@ def extract_context_from_sub_slug(sub_slug, sub_url):
|
|||
|
||||
class Placeholder:
|
||||
def __init__(
|
||||
self, key, name=None, acquired=False, optional=False, render=True, cell=None, force_synchronous=False
|
||||
self,
|
||||
key,
|
||||
name=None,
|
||||
acquired=False,
|
||||
optional=False,
|
||||
render=True,
|
||||
cell=None,
|
||||
force_synchronous=False,
|
||||
outer_tag=None,
|
||||
):
|
||||
self.key = key
|
||||
self.name = name
|
||||
|
@ -145,6 +153,9 @@ class Placeholder:
|
|||
self.render = render
|
||||
self.cell = cell
|
||||
self.force_synchronous = force_synchronous
|
||||
if outer_tag is True:
|
||||
outer_tag = 'div'
|
||||
self.outer_tag = outer_tag
|
||||
|
||||
def get_name(self):
|
||||
if self.cell:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{% load i18n %}
|
||||
{% if render %}
|
||||
{% if placeholder_options.fx_grid_layout %}<div class="combo-placeholder {{ placeholder_options.fx_grid_layout }}">{% endif %}
|
||||
{% if outer_tag %}<{{outer_tag|default:"div"}} class="combo-placeholder combo-placeholder--{{ placeholder.key }}">{% endif %}
|
||||
{% if placeholder_options.fx_grid_layout %}<div class="{{ placeholder_options.fx_grid_layout }}">{% endif %}
|
||||
{% if render_skeleton %}
|
||||
{{ skeleton }}
|
||||
{% endif %}
|
||||
|
@ -17,4 +18,5 @@
|
|||
><div>{% render_cell cell %}</div></div>
|
||||
{% endfor %}
|
||||
{% if placeholder_options.fx_grid_layout %}</div>{% endif %}
|
||||
{% if outer_tag %}</{{outer_tag|default:"div"}}>{% endif %}
|
||||
{% endif %}
|
||||
|
|
|
@ -111,6 +111,8 @@ def placeholder(context, placeholder_name, **options):
|
|||
context['skeleton'] = ''
|
||||
|
||||
if not context.get('placeholder_search_mode'):
|
||||
if len(context['cells']) and placeholder.outer_tag:
|
||||
context['outer_tag'] = placeholder.outer_tag
|
||||
for cell in [x for x in context['cells'] if hasattr(x, 'get_repeat_template')]:
|
||||
repeat_template = cell.get_repeat_template(context)
|
||||
if not repeat_template:
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "combo/page_template.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block combo-content %}
|
||||
<div id="main-content">
|
||||
{% trans "Content" as name %}
|
||||
{% placeholder "content" name=name outer_tag=True %}
|
||||
</div>
|
||||
<div id="sidebar">
|
||||
{% trans "Sidebar" as name %}
|
||||
{% placeholder "sidebar" name=name outer_tag="aside" %}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -963,6 +963,32 @@ def test_synchronous_placeholder(app):
|
|||
resp = app.get('/foo/', status=200)
|
||||
|
||||
|
||||
def test_outer_tag_placeholder(app):
|
||||
page = Page(title='foo', slug='foo', template_name='standard', order=0)
|
||||
page.save()
|
||||
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
with override_settings(
|
||||
COMBO_PUBLIC_TEMPLATES={
|
||||
'standard': {
|
||||
'name': 'Test',
|
||||
'template': 'combo/page_template_outer_tag_placeholder.html',
|
||||
}
|
||||
},
|
||||
TEMPLATES=templates_settings,
|
||||
):
|
||||
resp = app.get('/foo/', status=200)
|
||||
assert not resp.pyquery('div.combo-placeholder--content')
|
||||
assert not resp.pyquery('aside.combo-placeholder--sidebar')
|
||||
|
||||
TextCell.objects.create(page=page, placeholder='content', text='Foobar', order=0)
|
||||
TextCell.objects.create(page=page, placeholder='sidebar', text='Foobar', order=0)
|
||||
resp = app.get('/foo/', status=200)
|
||||
assert resp.pyquery('div.combo-placeholder--content')
|
||||
assert resp.pyquery('aside.combo-placeholder--sidebar')
|
||||
|
||||
|
||||
def test_redirects(app):
|
||||
Redirect.objects.all().delete()
|
||||
Page.objects.all().delete()
|
||||
|
|
Loading…
Reference in New Issue