Need your advice - how to show in breadcrumbs whole path to article or page? I've got code:
{% for ance in ancestors %}
<li>
{% if not forloop.last %}
<a href="{{ ance.get_absolute_url }}">{{ ance.get_menu_title }}</a>
{% else %}
<span class="active">{{ ance.get_menu_title }}</span>
{% endif %}
</li>
{% endfor %}
but it shows only "Home" and current page. How to modify it to show whole path in breadcrumbs?
I've found in file menu_tags.py something that could be a code that calls ancestors. At least there is a class ShowBreadcrumbs:
class ShowBreadcrumb(InclusionTag):
"""
Shows the breadcrumb from the node that has the same url as the current request
- start level: after which level should the breadcrumb start? 0=home
- template: template used to render the breadcrumb
"""
name = 'show_breadcrumb'
template = 'menu/dummy.html'
options = Options(
Argument('start_level', default=0, required=False),
Argument('template', default='menu/breadcrumb.html', required=False),
Argument('only_visible', default=True, required=False),
)
def get_context(self, context, start_level, template, only_visible):
try:
# If there's an exception (500), default context_processors may not be called.
request = context['request']
except KeyError:
return {'template': 'cms/content.html'}
if not (isinstance(start_level, int) or start_level.isdigit()):
only_visible = template
template = start_level
start_level = 0
try:
only_visible = bool(int(only_visible))
except:
only_visible = bool(only_visible)
ancestors = []
nodes = menu_pool.get_nodes(request, breadcrumb=True)
# Find home
home = None
root_url = unquote(reverse("pages-root"))
home = next((node for node in nodes if node.get_absolute_url() == root_url), None)
# Find selected
selected = None
selected = next((node for node in nodes if node.selected), None)
if selected and selected != home:
node = selected
while node:
if node.visible or not only_visible:
ancestors.append(node)
node = node.parent
if not ancestors or (ancestors and ancestors[-1] != home) and home:
ancestors.append(home)
ancestors.reverse()
if len(ancestors) >= start_level:
ancestors = ancestors[start_level:]
else:
ancestors = []
context['ancestors'] = ancestors
context['template'] = template
return context
register.tag(ShowBreadcrumb)
def _raw_language_marker(language, lang_code):
return language
def _native_language_marker(language, lang_code):
with force_language(lang_code):
return force_text(ugettext(language))
def _current_language_marker(language, lang_code):
return force_text(ugettext(language))
def _short_language_marker(language, lang_code):
return lang_code
MARKERS = {
'raw': _raw_language_marker,
'native': _native_language_marker,
'current': _current_language_marker,
'short': _short_language_marker,
}