【问题标题】:Link to other page in Drupal 8链接到 Drupal 8 中的其他页面
【发布时间】:2018-10-05 05:44:05
【问题描述】:

在 Drupal 7 中,我使用以下代码链接到其他页面。我有 "Service" block 并且在那个 block 里面,我是这样写的。

<?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”,而且我不知道如何编写代码来连接其他页面。
有人帮我吗?
谢谢。

【问题讨论】:

标签: php twig block drupal-8 base-url


【解决方案1】:

在 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') }}

【讨论】:

    【解决方案2】:

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

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

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

    在这里,{{directory }} 将解析为您当前主题的目录。 用于准备指向其他字段的链接。见上面提到的drupal页面

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-03
      • 2015-02-05
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      相关资源
      最近更新 更多