2016-09-26 60 views
0

我在我的网站上有几个产品页面,它们将具有相同的索引和页面设置,但具有不同的url路径。我想重新使用该模板,但过滤结果只显示该索引页的子对象。为多个列表重复使用W Index目录模板

例如:

目前

www.../carnival - index page that displays all child objects 
www.../carnival/rides-games - child page of carnival 
www.../carnival/etc... 

我想使用该网站的其他部分相同的索引页:

www.../catering - index page that displays all child objects 
www.../catering/fun-food - child page of catering 
www.../catering/etc... 

但是,当我使用相同的索引页面并访问我的carnival页面,我也看到了所有的餐饮对象。

下面是我的代码 - 请帮助我;我知道必须有一个干这种方式。谢谢。

standard_index_page.html

{% block content %} 
... 
{% standard_index_listing %} 
... 
{% endblock %} 

standard_index_listing.html

{% if pages %} 
    {% for pages in pages %} 
    <div class="col-xs-6 col-sm-4 col-md-3 mt20 hover-float"> 
     <div class="team-two"> 
     {% if pages.feed_image %} 
      {% image pages.feed_image original as img %} 
      <div class="team-one" data-animation="zoomIn" data-animation-delay="100" style="background: url('{{ img.url }}') no-repeat top center; background-size: cover"></div> 
     {% endif %} 
     <h5>{{ pages.title }}</h5> 
     <small><a href="{% pageurl pages %}" class="color-pasific">Learn More </a></small> 
     </div> 
    </div> 
    {% endfor %} 
{% endif %} 

home_tags.py

@register.inclusion_tag(
    'home/tags/standard_index_listing.html', 
    takes_context=True 
) 
def standard_index_listing(context): 
    pages = StandardPage.objects.live() 
    return { 
     'pages': pages.select_related('feed_image'), 
     'request': context['request'], 
    } 

回答

1

context字典内传递给standard_index_listing标记,您可以使用当前页面'page'。您可以使用此过滤查询集(见http://docs.wagtail.io/en/v1.6.2/reference/pages/queryset_reference.html#module-wagtail.wagtailcore.query):

def standard_index_listing(context): 
    pages = StandardPage.objects.live().child_of(context['page']) 
    return { 
     'pages': pages.select_related('feed_image'), 
     'request': context['request'], 
    } 
+0

你也可以做'页=背景[ '页'] get_children()生活()'。 – 404