How can I get information about the subsequent FeinCMS content block in a template rendering a RichTextContent
?
Obtaining something like the class name would be ideal, but also access to fields of the model would help me.
How can I get information about the subsequent FeinCMS content block in a template rendering a RichTextContent
?
Obtaining something like the class name would be ideal, but also access to fields of the model would help me.
Out-of-the-box here's no way to look ahead to the next content block. What exactly are you trying to accomplish?
We often had to wrap multiple content blocks of the same type in another <div>
with a certain class. We accomplished this with a custom templatetag (using the django-ttag library):
import ttag
from feincms.templatetags.feincms_tags import _render_content
@register.tag
class CmsRenderRegion(ttag.Tag):
'''
Renders a FeinCMS template region, just like feincms.templatetags.feincms_tags.render_region.
However, it checks each content type for a field "wrapper_css_classes". If the content type
has such a class, it adds a surrounding <div class="{{ wrapper_css_classes }}"> to all sequential
content types with that class.
'''
page = ttag.Arg()
region = ttag.Arg()
request = ttag.Arg()
def render(self, context):
data = self.resolve(context)
s = u''
last_wrapper = None
for content in getattr(data['page'].content, data['region']):
current_wrapper = getattr(content, 'wrapper_css_tag', None)
if current_wrapper is None:
if last_wrapper is not None:
# close the previous wrapper
s += u'</%s>' % last_wrapper[0]
else:
if last_wrapper is None:
s += u'<%s class="%s">' % current_wrapper
elif last_wrapper != current_wrapper:
s += u'</%s><%s class="%s">' % (
last_wrapper[0], current_wrapper[0], current_wrapper[1])
last_wrapper = current_wrapper
s += _render_content(content, request=data['request'], context=context)
if last_wrapper is not None:
s += u'</%s>' % last_wrapper[0]
return s
In your template, instead of {% feincms_render_region feincms_page 'region' request %}
you would then use {% cms_render_region feincms_page 'region' request %}
to render the region.
You can adapt the logic of the render template to whatever your trying to accomplish. The content blocks are in page.content.{{ region }}
, for instance page.content.sidebar
.