Skip to content
Snippets Groups Projects
Commit c169d17e authored by Dylann Cordel's avatar Dylann Cordel :crossed_swords:
Browse files

templating

parent 35905c27
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ INSTALLED_APPS = [ ...@@ -27,7 +27,7 @@ INSTALLED_APPS = [
CMS_HIGHLIGHTED_CONTENT_ITEMS_MODELS = ( CMS_HIGHLIGHTED_CONTENT_ITEMS_MODELS = (
# format: ('app_name', ('SomeModel', 'AnOther', )), # format: ('app_name', ('SomeModel', 'AnOther', )),
('news', ('News', ),), ('news', ('News', ),),
('fosm', ('Chronicle', 'Note', 'Dossier', 'Conference')), ('fosm', ('Project', 'Event', 'News')),
) )
``` ```
......
...@@ -53,6 +53,7 @@ class HighlightedContentPluginBase(CMSPluginBase): ...@@ -53,6 +53,7 @@ class HighlightedContentPluginBase(CMSPluginBase):
def render(self, context, instance, placeholder): def render(self, context, instance, placeholder):
items = self.get_items(context, instance, placeholder) items = self.get_items(context, instance, placeholder)
context.update({ context.update({
'title': instance.title,
'object_list': items, 'object_list': items,
'count': (items.count() if hasattr(items, 'count') and callable(items.count) 'count': (items.count() if hasattr(items, 'count') and callable(items.count)
else len(items)), else len(items)),
......
...@@ -107,8 +107,8 @@ class HighlightedContentItemBase(models.Model): ...@@ -107,8 +107,8 @@ class HighlightedContentItemBase(models.Model):
def get_template(self): def get_template(self):
"""returns the template to use to render this item as a item""" """returns the template to use to render this item as a item"""
if self.content_type_id not in self._templates: if self.content_type_id not in self._templates:
kwargs = {'app_label': self._meta.app_label, kwargs = {'app_label': self.content_type.app_label,
'model_name': self._meta.model_name} 'model_name': self.content_type.model}
templates = ['%(app_label)s/%(model_name)s/highlighted_content_item.html' % kwargs, templates = ['%(app_label)s/%(model_name)s/highlighted_content_item.html' % kwargs,
'%(app_label)s/highlighted_content_item.html' % kwargs, '%(app_label)s/highlighted_content_item.html' % kwargs,
'cms_highlighted_content/highlighted_content_item.html'] 'cms_highlighted_content/highlighted_content_item.html']
......
{% load i18n sekizai_tags static %} {% load i18n %}
{% if count %}
{% if items_count %} <section class="mod__highlighted_content">
<section id="highlighted_content_{{ instance.pk }}" class="mod__highlighted_content" role="region" data-highlighted_content="{{ highlighted_content_opts }}" {% if title %} aria-labelledby="highlighted_content_{{ instance.pk }}_heading"{% endif %}> {% block highlighted_list_header %}
{% if title %}<h1 id="highlighted_content_{{ instance.pk }}_heading">{{ title }}</h1>{% endif %} {% if instance.title %}
<div class="viewport"> <h1>
<ul class="overview"> {% if instance.page_link %}
{% for item in items %} <a href="{{ instance.page_link.get_absolute_url }}">{{ instance.title }}</a>
<li class="item {{ item.content_type.app_label }}_{{ item.content_type.model }}" aria-label="{{ item }}">{% include item.get_template with item=item %}</li> {% else %}
{{ instance.title }}
{% endif %}
</h1>
{% endif %}
{% endblock %}
{% block highlighted_list %}
<div class="list">
{% for highlighted_item in object_list %}
{% block highlighted_list_item %}
{% include highlighted_item.get_template with highlighted_item=highlighted_item object=highlighted_item.item %}
{% endblock %}
{% endfor %} {% endfor %}
</ul> </div>
</div> {% endblock %}
</section> </section>
{% else %}
{% block highlighted_no_object %}{% endblock %}
{% endif %} {% endif %}
<script type="text/javascript">
window.highlighted_contents = [] || window.highlighted_contents ;
window.highlighted_contents.push('#highlighted_content_{{ instance.pk }}');
</script>
{% load static %} <div class="{{ highlighted_item.content_type.model }}">
<article> {% with object.get_absolute_url as url %}
<h1 class="title">{{ object }}</h1> {% block highlighted_item_header %}
<img class="background" src="https://durian.blender.org/wp-content/uploads/2010/05/3.2d.png" alt="" /> <header>
<p class="summary"> {% block highlighted_item_header_content %}
This is a sample template you should override. {% if url %}
In this exemple, we use an IMG tag to display the image of the item. <h2><a href="{{ url }}">{{ highlighted_item }}</a></h2>
</p> {% else %}
</article> <h2>{{ highlighted_item }}</h2>
{% endif %}
{% comment %} {% endblock %}
</header>
<article style="background-image: url('https://durian.blender.org/wp-content/uploads/2010/05/3.2d.png');"> {% endblock %}
<h1 class="title">{{ object }}</h1> <div>
<p class="summary">This is an other sample template with the image as background.</p> {% block highlighted_item_body_content %}
</article>
<div>
<h1 class="title">{{ object }}</h1>
<video src="http://mirrorblender.top-ix.org/movies/sintel-1024-surround.mp4" autoplay poster="https://durian.blender.org/wp-content/uploads/2010/05/3.2d.png">
<a href="http://mirrorblender.top-ix.org/movies/sintel-1024-surround.mp4" download="sintel-1024-surround.mp4">
<img class="background" src="https://durian.blender.org/wp-content/uploads/2010/05/3.2d.png" alt="" /> <img class="background" src="https://durian.blender.org/wp-content/uploads/2010/05/3.2d.png" alt="" />
</a> <p class="summary">
</video> This is a sample template you should override.
<p class="summary">Another exemple with a video.</p> In this exemple, we use an IMG tag to display the image of the item.
</p>
{% endblock %}
</div>
{% endwith %}
</div> </div>
{% endcomment %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment