I am having trouble constructing a link with mailto in twig template. The code is below.

{% set mail = 'mailto:' ~ content.field_email %}
{{ link(content.field_sign, mail, { 'target':['_blank']} ) }}

content.field_email is a comment field.

The link is printed as mailto:Array

When I use {{ content.field_email }} , the email value is printing correctly. But when I concatenate , it is somehow treated as an array.

Any idea?


denizlive@gmail.com created an issue. See original summary.

Cottser’s picture

Issue tags: -Drupal 8.x, -mailto

content.field_email Is most likely a render array, not a string.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

Try rendering it to a string: {% set mail = 'mailto:' ~ content.field_email|render %}

Nil.Ned’s picture

#4 it works! ;-) Thanxs