Skip to content

A collection of Django templatetags to flexibly incorporate links and breadcrumbs from app pages to the homepage of a project

License

Notifications You must be signed in to change notification settings

mfcovington/django-project-home-templatetags

Repository files navigation

django-project-home-templatetags

django-project-home-templatetags is a collection of Django templatetags to flexibly incorporate links and breadcrumbs from app pages to the homepage of a project.

If PROJECT_HOME_NAMESPACE is not defined to settings.py, these template tags are silenced.

Source code is available on GitHub at mfcovington/django-project-home-templatetags.

PyPI

pip install django-project-home-templatetags

GitHub (development branch)

pip install git+http://github.com/mfcovington/django-project-home-templatetags.git@develop

Add project_home_tags to INSTALLED_APPS in settings.py:

INSTALLED_APPS = (
    ...
    'project_home_tags',
)

Specify the PROJECT_HOME_NAMESPACE in settings.py:

PROJECT_HOME_NAMESPACE = 'project_name:index_view'

Rather than using an internal namespace, you can also set PROJECT_HOME_NAMESPACE to a specific URL:

PROJECT_HOME_NAMESPACE = 'djangoproject.com'

By default, a link created with a project_home_tags template tag has 'Home' as its text. This can be overridden by defining an optional project-wide label with PROJECT_HOME_LABEL in settings.py:

PROJECT_HOME_LABEL = 'Homepage'    # Optional; Default is 'Home'

Both the default and the project-wide label can be overridden by passing a string to the template tag. For example:

{% project_home_breadcrumb_bs4 'Custom Label' %}

Loads the project home template tags in your Django template.

A template tag to return the project's home URL.

{% load project_home %}

<a href="{% project_home_url %}">Home</a>

If settings.PROJECT_HOME_NAMESPACE is defined as 'project_name:index_view', this is equivalent to:

<a href="{% url 'project_name:index_view' %}">Home</a>

A template tag to return the project's home URL and label formatted as a Bootstrap 3 breadcrumb.

{% load project_home %}

<ol class="breadcrumb">
  {% project_home_breadcrumb_bs3 %}    {# <--- #}
  <li><a href="{% url 'app:namespace' %}">List of Objects</a></li>
  <li class="active">Object Detail</li>
</ol>

If settings.PROJECT_HOME_NAMESPACE is defined as 'project_name:index_view', this is equivalent to:

<ol class="breadcrumb">
  <li><a href="{% url 'project_name:index_view' %}">Home</a></li>    {# <--- #}
  <li><a href="{% url 'app:namespace' %}">List of Objects</a></li>
  <li class="active">Object Detail</li>
</ol>

A template tag to return the project's home URL and label formatted as a Bootstrap 4 breadcrumb.

{% load project_home %}

<ol class="breadcrumb">
  {% project_home_breadcrumb_bs4 %}    {# <--- #}
  <li class="breadcrumb-item" aria-label="breadcrumb"><a href="{% url 'app:namespace' %}">List of Objects</a></li>
  <li class=" breadcrumb-item active" aria-label="breadcrumb" aria-current="page">Object Detail</li>
</ol>

If settings.PROJECT_HOME_NAMESPACE is defined as 'project_name:index_view', this is equivalent to:

<ol class="breadcrumb">
  <li class="breadcrumb-item" aria-label="breadcrumb"><a href="{% url 'project_name:index_view' %}">Home</a></li>    {# <--- #}
  <li class="breadcrumb-item" aria-label="breadcrumb"><a href="{% url 'app:namespace' %}">List of Objects</a></li>
  <li class=" breadcrumb-item active" aria-label="breadcrumb" aria-current="page">Object Detail</li>
</ol>

Version 0.2.1

About

A collection of Django templatetags to flexibly incorporate links and breadcrumbs from app pages to the homepage of a project

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages