2017-09-25 5 views
0

J'essaie de comprendre comment afficher les balises appartenant à un article créé dans le plugin Aldryn NewsBlog. Malheureusement, je ne trouve aucune documentation sur comment le faire.Liste des balises d'un message dans Django CMS et Aldryn NewsBlog

J'étais capable d'afficher des catégories en utilisant le code suivant.

<span style="margin: 0; display: block"> 
    <h4 style="display:inline-flex">Categories:</h4> 
     {% for category in article.categories.all %} 
      <a href="/articles/category/{{category.name|lower}}">{{ category.name }} {% if not forloop.last %}, {% endif %}</a> 
     {% endfor %} 
</span> 

Pour les tags, je suis en utilisant ce code:

<span style="margin: 0; padding-bottom: 0; display: block"> 
    <h4 style="display:inline-flex">Tags:</h4> 
     {% for tag in article.tag %} 
      <a href="/articles/tag/{{tag.name|lower}}">{{ tag.name }} {% if not forloop.last %}, {% endif %}</a> 
     {% endfor %} 
</span> 

Qu'est-ce que je fais mal? Quelqu'un pourrait-il me dire comment afficher les balises?

Répondre

1

c'est le modèle de balises officiel de aldryn-Newsblog, il a travaillé pour moi:

{% load i18n apphooks_config_tags %} 

<div class="aldryn aldryn-newsblog aldryn-newsblog-tags"> 
<ul class="list-unstyled"> 
    <li{% if not newsblog_tag %} class="active"{% endif %}> 
     <a href="{% namespace_url "article-list" namespace=instance.app_config.namespace default='' %}">{% trans "All" %}</a> 
    </li> 
    {% for tag in tags %} 
     <li{% if newsblog_tag.id == tag.id %} class="active"{% endif %}> 
      <a href="{% namespace_url "article-list-by-tag" tag.slug namespace=instance.app_config.namespace default='' %}"> 
       {{ tag.name }} 
       <span class="badge">{{ tag.article_count }}</span> 
      </a> 
     </li> 
    {% endfor %} 
</ul> 

https://github.com/aldryn/aldryn-newsblog/blob/master/aldryn_newsblog/boilerplates/bootstrap3/templates/aldryn_newsblog/plugins/tags.html

vous avez raison, c'est-ce que vous cherchez, avec article.tags.all:

{% if article.tags.exists %} 
    <ul style="margin-left: 0"> 
     {% for tag in article.tags.all %} 
      <li class="tags"><a href="{% namespace_url 'article-list-by-tag' tag=tag.slug namespace=namespace default='' %}">{{ tag.name }}</a></li> 
      {% if not forloop.last %}<span class="separator tags-separator">|</span> {% endif %} 
     {% endfor %} 
    </ul> 
{% endif %} 
+0

Affiche-t-il tous les tags ou seulement les tags d'un article particulier? – MadPhysicist