|
| 1 | +******************************** |
| 2 | +django-project-home-templatetags |
| 3 | +******************************** |
| 4 | + |
| 5 | +``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. |
| 6 | + |
| 7 | +If ``PROJECT_HOME_NAMESPACE`` is not defined to ``settings.py``, these template tags are silenced. |
| 8 | + |
| 9 | +Source code is available on GitHub at `mfcovington/django-project-home-templatetags <https://github.com/mfcovington/django-project-home-templatetags>`_. |
| 10 | + |
| 11 | +.. contents:: :local: |
| 12 | + |
| 13 | + |
| 14 | +Installation |
| 15 | +============ |
| 16 | + |
| 17 | +**PyPI** |
| 18 | + |
| 19 | +.. code-block:: sh |
| 20 | +
|
| 21 | + pip install django-project-home-templatetags |
| 22 | +
|
| 23 | +
|
| 24 | +**GitHub (development branch)** |
| 25 | + |
| 26 | +.. code-block:: sh |
| 27 | +
|
| 28 | + pip install git+http://github.com/mfcovington/django-project-home-templatetags.git@develop |
| 29 | +
|
| 30 | +
|
| 31 | +Configuration |
| 32 | +============= |
| 33 | + |
| 34 | +Add ``project_home_tags`` to ``INSTALLED_APPS`` in ``settings.py``: |
| 35 | + |
| 36 | +.. code-block:: python |
| 37 | +
|
| 38 | + INSTALLED_APPS = ( |
| 39 | + ... |
| 40 | + 'project_home_tags', |
| 41 | + ) |
| 42 | +
|
| 43 | +
|
| 44 | +Specify the ``PROJECT_HOME_NAMESPACE`` in ``settings.py``: |
| 45 | + |
| 46 | +.. code-block:: python |
| 47 | +
|
| 48 | + PROJECT_HOME_NAMESPACE = 'project_name:index_view' |
| 49 | +
|
| 50 | +
|
| 51 | +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``: |
| 52 | + |
| 53 | +.. code-block:: python |
| 54 | +
|
| 55 | + PROJECT_HOME_LABEL = 'Homepage' # Optional; Default is 'Home' |
| 56 | +
|
| 57 | +
|
| 58 | +Both the default and the project-wide label can be overridden by passing a string to the template tag. For example: |
| 59 | + |
| 60 | +.. code-block:: python |
| 61 | +
|
| 62 | + {% project_home_breadcrumb_bs4 'Custom Label' %} |
| 63 | +
|
| 64 | +
|
| 65 | +Template Tags |
| 66 | +============= |
| 67 | + |
| 68 | +``{% load project_home %}`` |
| 69 | +-------------------------------- |
| 70 | + |
| 71 | +Loads the project home template tags in your Django template. |
| 72 | + |
| 73 | + |
| 74 | +``{% project_home_url %}`` |
| 75 | +-------------------------- |
| 76 | + |
| 77 | +A template tag to return the project's home URL. |
| 78 | + |
| 79 | +.. code-block:: python |
| 80 | +
|
| 81 | + {% load project_home %} |
| 82 | +
|
| 83 | + <a href="{% project_home_url %}">Home</a> |
| 84 | +
|
| 85 | +
|
| 86 | +If ``settings.PROJECT_HOME_NAMESPACE`` is defined as ``'project_name:index_view'``, this is equivalent to: |
| 87 | + |
| 88 | +.. code-block:: python |
| 89 | +
|
| 90 | + <a href="{% url 'project_name:index_view' %}">Home</a> |
| 91 | +
|
| 92 | +
|
| 93 | +``{% project_home_breadcrumb_bs3 %}`` |
| 94 | +------------------------------------- |
| 95 | + |
| 96 | +A template tag to return the project's home URL and label formatted as a `Bootstrap 3 breadcrumb <https://getbootstrap.com/docs/3.3/components/#breadcrumbs>`_. |
| 97 | + |
| 98 | +.. code-block:: python |
| 99 | +
|
| 100 | + {% load project_home %} |
| 101 | +
|
| 102 | + <ol class="breadcrumb"> |
| 103 | + {% project_home_breadcrumb_bs3 %} {# <--- #} |
| 104 | + <li><a href="{% url 'app:namespace' %}">List of Objects</a></li> |
| 105 | + <li class="active">Object Detail</li> |
| 106 | + </ol> |
| 107 | +
|
| 108 | +
|
| 109 | +If ``settings.PROJECT_HOME_NAMESPACE`` is defined as ``'project_name:index_view'``, this is equivalent to: |
| 110 | +
|
| 111 | +.. code-block:: python |
| 112 | +
|
| 113 | + <ol class="breadcrumb"> |
| 114 | + <li><a href="{% url 'project_name:index_view' %}">Home</a></li> {# <--- #} |
| 115 | + <li><a href="{% url 'app:namespace' %}">List of Objects</a></li> |
| 116 | + <li class="active">Object Detail</li> |
| 117 | + </ol> |
| 118 | +
|
| 119 | +
|
| 120 | +``{% project_home_breadcrumb_bs4 %}`` |
| 121 | +------------------------------------- |
| 122 | +
|
| 123 | +A template tag to return the project's home URL and label formatted as a `Bootstrap 4 breadcrumb <https://getbootstrap.com/docs/4.1/components/breadcrumb/>`_. |
| 124 | +
|
| 125 | +.. code-block:: python |
| 126 | +
|
| 127 | + {% load project_home %} |
| 128 | +
|
| 129 | + <ol class="breadcrumb"> |
| 130 | + {% project_home_breadcrumb_bs4 %} {# <--- #} |
| 131 | + <li class="breadcrumb-item" aria-label="breadcrumb"><a href="{% url 'app:namespace' %}">List of Objects</a></li> |
| 132 | + <li class=" breadcrumb-item active" aria-label="breadcrumb" aria-current="page">Object Detail</li> |
| 133 | + </ol> |
| 134 | +
|
| 135 | +
|
| 136 | +If ``settings.PROJECT_HOME_NAMESPACE`` is defined as ``'project_name:index_view'``, this is equivalent to: |
| 137 | +
|
| 138 | +.. code-block:: python |
| 139 | +
|
| 140 | + <ol class="breadcrumb"> |
| 141 | + <li class="breadcrumb-item" aria-label="breadcrumb"><a href="{% url 'project_name:index_view' %}">Home</a></li> {# <--- #} |
| 142 | + <li class="breadcrumb-item" aria-label="breadcrumb"><a href="{% url 'app:namespace' %}">List of Objects</a></li> |
| 143 | + <li class=" breadcrumb-item active" aria-label="breadcrumb" aria-current="page">Object Detail</li> |
| 144 | + </ol> |
| 145 | +
|
| 146 | +
|
| 147 | +*Version 0.1.0* |
0 commit comments