Skip to main content

Drupal 8, Twig: How to add destination to complex twig templates

This is a kind of complex example about how you can add a destination url parameter with twig functionality and a custom route from a custom module.routing.yml url.

{% set redirectPath = path('event_user_sync.registration', {'node': node_data.node.id}) %}

<h2>{{ node_data.block_title }}</h2>
<p>{{ node_data.description }}</p>

{# Logic for showing,hiding the registration button #}
{% if node_data.event_needs_registration %}
	{# event might be full, or in passed date #}
	{% if node_data.can_register %}

		{% if node_data.is_anonymous %}
			<a class="d-block btn-block-sidebar btn-block-sidebar-alt btn-block-sidebar-lg mb-3" href="{{ path('user.register',{},{'query':{'destination': redirectPath }}) }}">{{ 'Εγγραφή'|t }}</a>
		{% else %}
			<a class="d-block btn-block-sidebar btn-block-sidebar-alt btn-block-sidebar-lg mb-3" href="{{ url('event_user_sync.registration', {'node': node_data.node.id}) }}">{{ 'Εγγραφή'|t }}</a>
		{% endif %}

	{% else %}
		<span class="text-danger">{{ 'Δεν μπορείτε πλέον, να δηλώσετε συμμετοχή'|t }}</span>
	{% endif %}

{% endif %}

 

frontend