Skip to content

Commit

Permalink
Allow using variable as identifier in static_alias template tag (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanw authored Aug 10, 2023
1 parent ab22c8d commit d67e13c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

Unreleased
==========
* fix: Allow using a variable as the identifier in static_alias template tag

2.0.0rc1
========
* Django 4.0, 4.1, and 4.2 support added
Expand Down
2 changes: 1 addition & 1 deletion djangocms_alias/templatetags/djangocms_alias_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class StaticAlias(Tag):
"""
name = 'static_alias'
options = PlaceholderOptions(
Argument('static_code', resolve=False),
Argument('static_code', resolve=True),
MultiValueArgument('extra_bits', required=False, resolve=False),
blocks=[
('endstatic_alias', 'nodelist'),
Expand Down
19 changes: 19 additions & 0 deletions tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,22 @@ def page_edit_url(lang):

self.assertIsNotNone(alias.get_content("en", show_draft_content=True))
self.assertIsNotNone(alias.get_content("de", show_draft_content=True))

def test_alias_rendered_when_identifier_is_variable(self):
alias_template = """{% load djangocms_alias_tags %}{% static_alias foo_variable %}""" # noqa: E501

alias = self._create_alias(static_code="some_unique_id")
add_plugin(
alias.get_placeholder(self.language),
'TextPlugin',
language=self.language,
body='Content Alias 1234',
)

output = self.render_template_obj(
alias_template,
{'foo_variable': "some_unique_id"},
self.get_request('/'),
)

self.assertEqual(output, "Content Alias 1234")

0 comments on commit d67e13c

Please sign in to comment.