Link 到 Drupal 8 中的其他页面

Link to other page in Drupal 8

在 Drupal 7 中,我使用以下代码 link 到其他页面。我有“Serviceblock,在那个块里面,我这样写。

<?php
global $base_url;    
global $base_path;   
$link = $base_url . '/sites/all/themes/bootstrap_business/images';
?>
<div><img alt="" src="<?php print $link?>/customer.png" /></div>
<p><a href="<?php echo $base_url;?>/en/test#collapseOne"> Service</a></p>

我用PHP保存文本格式。
但是现在 Drupal 8,我们没有文本格式选项 "PHP" 而且我也不知道如何编写代码来连接其他页面。
有人帮我吗?
谢谢。

参见:https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templates

在您的示例中,您需要指定主题目录。只需使用:

<img src="/{{ directory }}/images/xyz.jpg">

此处,{{directory }} 将解析为您当前主题的目录。 用于准备指向其他字段的链接。请参阅上面提到的 drupal 页面

在 drupal 8 中,您可以使用 hook_preprocess_HOOK() 将变量传递给 twig 文件并调用您的变量,如

<header class="main-header">
  {{ title_prefix }}
  {% if page.header and logged_in %}
    {{ page.header }}
  {% endif %}
  {% if not logged_in %}
  <a href="{{ front_page }}" title="{{ 'Home'|t }}" rel="home" id="logo" class="logo">
    <img src="{{ base_path }}themes/custom/mytheme/logo-login.png" alt="{{ 'Home'|t }}" />
  </a>
  <h2 class="login-logo">{{ site_name }}</h2>
  {% endif %}
  {{ title_suffix }}
</header>

详情请见https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templates

您还可以使用

包含其他页面
{# this template is located in templates/layout.html.twig #}
{% extends "layout.html.twig" %}

{# this template is located in templates/user/profile.html.twig #}
{{ include('user/profile.html.twig') }}