Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Nov 8, 2024
1 parent 73a90ad commit 7f6340e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,28 @@ models or forms.
To render the link field in a template, use the ``LinkDict`` property ``url`` or
the new template tag ``to_url``. The ``type`` property returns the link type::

{% load djangocms_link_tags %}
{# Variant 1 #}
{% if obj.link %}
<a href="{{ obj.link|to_url }}">Link</a>
<a href="{{ obj.link.url }}">Link available</a>
{% endif %}

{# Variant 2 #}
{% load djangocms_link_tags %}
{% if obj.link %}
<a href="{{ obj.link.url }}"
{% if obj.link.type == "external_link" %} target="_blank"{% endif %}
>Link available</a>
<a href="{{ obj.link|to_url }}">Link</a>
{% endif %}

{# Variant 3 #}
{% with url=obj.link|to_url %}
{% if url %}
<a href="{{ url }}">Link available</a>
{% endif %}
{% endwith %}

{% if obj.link.type == "external_link" %}
<a href="{{ obj.link.url }}">External link</a>
{% endif %}


To turn the ``LinkField``'s ``LinkDict`` dictionary into a URL in python code,
use the ``url`` property. (It will hit the database when needed. Results are
Expand Down

0 comments on commit 7f6340e

Please sign in to comment.