Skip to content

Refactor: define vocab_url Twig filter for constructing links to vocabularies #1565

@osma

Description

@osma

Description of the enhancement

Our Skosmos 3 Twig templates contain code like this for constructing the URL to the home page:

<a id="skosmos-logo-top" href="{{ request.lang }}/{% if request.contentLang and request.contentLang != request.lang %}?clang={{ request.contentLang }}{% endif %}{% if request.queryParam('anylang') == 'on' %}{% if request.contentLang == request.lang %}?{% else %}&{% endif %}anylang=on{% endif %}">

(the same kind of snippet appears at least two more times further down in the same file)

This is a very cumbersome and fragile way of constructing the URL, which usully amounts to something like /en or /fi or /fi?clang=en . For other kinds of URLs, we already have defined a custom filter link_url for Twig. I think a similar filter, perhaps called vocab_url should be defined and used here, which would move the URL construction logic away from the Twig template and into the PHP backend code, which is better suited for this kind of conditional URL string manipulation.

Who are the users that would benefit from the enhancement and how?

Developers trying to keep sane

What new functionalities would the enhancement make possible?

Make the Twig template cleaner and easier to understand

Why is the enhancement important?

Refactoring early is good.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions