2017-01-24 13 views
0

すべてのページがツリー(親/子供)にある場合、このような標準的なセキレイブレッドクラム・システムは完璧に動作します:RoutablePageMixinとパン粉

{% block main %} 
    {% if self.get_ancestors|length > 1 %} 
     <ul class="breadcrumb"> 
      {% for page in self.get_ancestors %} 
       {% if page.is_root == False and page.url != '/' %} 
        <li><a href="{% pageurl page %}">{{ page.title }}</a></li> 
       {% endif %} 
      {% endfor %} 
      <li class="active">{{ self.title }}</li> 
     </ul> 
    {% endif %} 
{% endblock main %} 

しかし、あなたのサブページの一部でない場合はそれが落ちます実際の子供は、代わりにRoutablePageMixinを使用します。ルーティング可能なページは実際には親のインスタンスとは異なるため、ブレッドクラム・トレイルはルーティング可能なページに移動することができません。

状況を検出して特殊なケースを検出するためにいくつかの追加情報をコンテキストに追加できると思っていましたが、すべてのWT URLメソッドが「親」ページ(つまり実際のインスタンス)のURLを返しますブレッドクラムで使用できるプログラム上の「タイトル」はありません。

子ページとルーティング可能なページで同じように機能するパンくずリストシステムを使用する最も良い方法はありますか?

答えて

0

私自身の質問に答える(ヒントはヒントありがとう)。以下のように、モデル内のルート定義では、何かを追加:

ctx['routed_title'] = 'Staff' 

が続いて上記のようなブレッドクラムの例を変更(文脈上の新しい要素が存在するかどうかを確認してパン粉に追加):

{% block main %} 
    {% if self.get_ancestors|length > 1 %} 
     <ul class="breadcrumb"> 
      {% for page in self.get_ancestors %} 
       {% if page.is_root == False and page.url != '/' %} 
        <li><a href="{% pageurl page %}">{{ page.title }}</a></li> 
       {% endif %} 
      {% endfor %} 
      {# If this is a routable, add non-parent/child link from context #} 
      {% if routed_title %} 
       <li><a href="{% pageurl page %}">{{ page.title }}</a></li> 
       <li class="active">{{ routed_title }}</li> 
      {% else %} 
       <li class="active">{{ self.title }}</li> 
      {% endif %} 
     </ul> 
    {% endif %} 
{% endblock main %} 
1

多分これはどんな助けでもかまいません。

@route(_(r'^detail/(?P<activity_slug>[-\w]+)/$')) 
def show_activity(self, request, activity_slug): 
    activity_model_class = self.activity_model_class 
    if not activity_model_class: 
     raise Http404('No activity model.') 
    else: 
     queryset = self.get_activity(activity_slug) 
     try: 
      activity = queryset.get() 
     except activity_model_class.DoesNotExist: 
      raise Http404('activity not found') 
     else: 
      self.current_url = self.get_url(
       'show_activity', 
       kwargs = {'activity_slug': activity_slug} 
      ) 

は今、ルーティング可能なページが

def get_context(self, request, *args, **kwargs): 
     context = super().get_context(request) 
     context['current_url']= self.current_url 
    return context 

current_urlを持っており、今では状況にあります。

+0

ロバートありがとう - しかし、あなたはどのようにこのテクニックのパンくずリストで使用するページタイトルにアクセスしますか? – shacker

+0

パン粉のパスの最後のページのタイトルですか? – Robert

+0

はい - このテクニックが持ち込むルーティング可能なページのタイトルです。私はそれをコンテキストにコード化することができます - 私のOPではself.titleと呼ばれる要素。 – shacker

関連する問題