Skip to main content
added 26 characters in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

file-link.html.twig

<span{{ attributes }}>{{ link|merge({'#attributes': {'target': '_blank'}}) }}</span>
{% if file_size %}
  {# @todo remove class before Drupal 9.0.0 #}
  <span class="file-size">({{ file_size }})</span>
{% endif %}

Alternatively, you can also solve this via preprocess.

/themes/mytheme/mytheme.theme

/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_file_link(&$variables) {
  $variables['link']['#url']->setOption('attributes', ['target' => '_blank']);
}

file-link.html.twig

<span{{ attributes }}>{{ link|merge({'#attributes': {'target': '_blank'}}) }}</span>
{% if file_size %}
  {# @todo remove class before Drupal 9.0.0 #}
  <span class="file-size">({{ file_size }})</span>
{% endif %}

Alternatively, you can also solve this via preprocess.

/themes/mytheme/mytheme.theme

/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_file_link(&$variables) {
  $variables['link']['#url']->setOption('attributes', ['target' => '_blank']);
}

file-link.html.twig

<span{{ attributes }}>{{ link|merge({'#attributes': {'target': '_blank'}}) }}</span>
{% if file_size %}
  {# @todo remove class before Drupal 9.0.0 #}
  <span class="file-size">({{ file_size }})</span>
{% endif %}

Alternatively, you can also solve this via preprocess.

mytheme.theme

/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_file_link(&$variables) {
  $variables['link']['#url']->setOption('attributes', ['target' => '_blank']);
}
added 253 characters in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

Youfile-link.html.twig

<span{{ attributes }}>{{ link|merge({'#attributes': {'target': '_blank'}}) }}</span>
{% if file_size %}
  {# @todo remove class before Drupal 9.0.0 #}
  <span class="file-size">({{ file_size }})</span>
{% endif %}

Alternatively, you can also solve this via preprocess.

/themes/mytheme/mytheme.theme

/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_file_link(&$variables) {
  $variables['link']['#url']->setOption('attributes', ['target' => '_none']'_blank']);
}

You can solve this via preprocess.

/themes/mytheme/mytheme.theme

/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_file_link(&$variables) {
  $variables['link']['#url']->setOption('attributes', ['target' => '_none']);
}

file-link.html.twig

<span{{ attributes }}>{{ link|merge({'#attributes': {'target': '_blank'}}) }}</span>
{% if file_size %}
  {# @todo remove class before Drupal 9.0.0 #}
  <span class="file-size">({{ file_size }})</span>
{% endif %}

Alternatively, you can also solve this via preprocess.

/themes/mytheme/mytheme.theme

/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_file_link(&$variables) {
  $variables['link']['#url']->setOption('attributes', ['target' => '_blank']);
}
deleted 155 characters in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

You can solve this via preprocess.

/themes/mytheme/mytheme.theme

/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_file_link(&$variables) {
  $variables['link']['#url']->setOption('attributes', ['target' => '_none']);
}

Side note: Also, could be solvable via file-link.html.twig, but you would have to allow twig to use the setOption method, by white listing it.

You can solve this via preprocess.

/themes/mytheme.theme

/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_file_link(&$variables) {
  $variables['link']['#url']->setOption('attributes', ['target' => '_none']);
}

Side note: Also, could be solvable via file-link.html.twig, but you would have to allow twig to use the setOption method, by white listing it.

You can solve this via preprocess.

/themes/mytheme/mytheme.theme

/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_file_link(&$variables) {
  $variables['link']['#url']->setOption('attributes', ['target' => '_none']);
}
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91
Loading