{% nava %}
Concept
Uses django.utils.format_html()
to output an <a>
element. When the request
object is included in the template tag, it will call curr()
to vet whether the element should include aria-current=page
. This makes it fit for desktop/mobile navbar link.
HTML fragment: <a>
tag for desktop/mobile navbar links.
Checks if link represented by reverse name url reversible
is the current path via the request, if it is provided.
In the latter case, on match of the request.path
to the reversible
, add aria-current=true
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reversible |
str
|
The value will be passed to the |
required |
text |
str | None
|
The text to incude within the anchor element, if any. Defaults to None. |
None
|
css |
str | None
|
If provided, will populate the |
None
|
request |
HttpRequest | None
|
The django http request object to ascertain the present path of the request. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
SafeText |
SafeText
|
The output anchor tag |
Source code in django_fragments/templatetags/fragments.py
curr
Returns a string aria-current
for use as an attribute when lhs
path matches the
reversible
value that will be passed to the django.urls.reverse()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lhs |
str
|
lhs stands for lefthand side, should be first positional element in the tag |
required |
reversible |
str
|
The value will be passed to the |
required |
Returns:
Name | Type | Description |
---|---|---|
SafeText |
SafeText
|
The text "aria-current=page" if a match occurs, otherwise "" |