在树枝中获取图像URL -- theming 领域 和 8 领域 和 files 领域 和 8 领域 和 files 领域 drupal 相关 的问题

Get Image URL in Twig


23
vote

问题

中文

我想通过树枝中的内联样式渲染图像作为背景图像。 我创建了一个名为bg_image的字段,并将其附加到标准普通页面。

摆弄几个小时后,我能够在node.html.twig

中获取图像URL
  {{ file_url(node.field_bg_image.0.entity.uri.value) }}   

但我无法将其工作在内部字段 - field-bg_image.html.twig

我可以随时从那里得到节点,所以我可以得到图像?

如何将图像URL获取用作内联样式? 我想也许我可以通过字段 - field-bg_image.html.twig到image.html.twig然后渲染

  {{ uri }}   

而不是

  <img{{ attributes.addClass(classes) }} />   

但除非我使用包含

,否则我无法将其传递到那里。
  {% include 'image.html.twig' with {'image': image, 'isFromField': isFromField} %}   

(Isfromfield是真的,它来自field - field-bg_image.html.twig) 但这也不起作用。图像永远不会呈现。

如果你能提供帮助,那么很高兴 - 我的PHP知识非常基础。 谢谢
英文原文

I want to render an image as a background image via an inline style in twig. I created a field called bg_image and attached it to the standard plain page.

After fiddling around for hours I was able to get the Image URL in node.html.twig

{{ file_url(node.field_bg_image.0.entity.uri.value) }} 

but I could not get it to work inside field--field-bg_image.html.twig

Can I get the node from there anyhow, so I can then get the image?

How can I get the image URL to use as inline style? I thought maybe I can pass a variable from field--field-bg_image.html.twig to image.html.twig and then just render

{{ uri }} 

instead of

<img{{ attributes.addClass(classes) }} /> 

but I could not get it to pass the variable there unless I use includes

{% include 'image.html.twig' with {'image': image, 'isFromField': isFromField} %} 

(isFromField is true, when it comes from the field--field-bg_image.html.twig) But that didn't work either. The Image was never rendered that way.

Would be very glad if you can help - my php knowledge is very basic. Thanks

              

回答列表

34
 
vote
vote
最佳答案
 

变量 parent::setUp()9 仅在节点模板(和页面模板中,如果URL包含节点)。现在,如果要在现场模板中访问节点字段,则必须在不同的位置查看:

field.html.twig:

  drush sset system.maintenance_mode TRUE0  

drush sset system.maintenance_mode TRUE1 是字段模板中的父实体,您可以从此实体访问任何字段(在您的情况下节点)。

如果要从实际字段访问原始值,最好遵循字段枝条的逻辑,并直接从现场项目对象 998877622 :< / p>

  drush sset system.maintenance_mode TRUE3  

编辑:获取图像样式的URL

安装模块 twig调整,您可以使用URI获取图像的URL风格:

  drush sset system.maintenance_mode TRUE4  

 

The variable node is only preloaded in the node template (and the page template, if the url contains the node). Now if you want to access node fields in a field template you have to look in a different place:

field.html.twig:

{{ file_url(element['#object'].field_image.0.entity.uri.value) }} 

element['#object'] is the parent entity in a field template and you can access any field from this entity (in your case the node).

If you want to access raw values from the actual field, it's better to follow the logic of the field twig and access the value inside of the items loop directly from the field item object #item:

{% for item in items %}   {{ file_url(item.content['#item'].entity.uri.value) }} {% endfor %} 

Edit: Get the url of an image style

Install the module Twig Tweak and you can use the uri to get the url of an image style:

{% for item in items %}   {{ item.content['#item'].entity.uri.value | image_style('thumbnail') }} {% endfor %} 
 
 
       
               
28
 
vote

只是提到,如果您想要在其中一个新的自定义块中执行此操作:

  {{ file_url(content.field_image['#items'].entity.uri.value) }}   
 

Just to mention that if you want to do the same in one of the new custom blocks this works:

{{ file_url(content.field_image['#items'].entity.uri.value) }} 
 
 
               
                               
3
 
vote

我在我的.theme文件中使用此代码:

  function THEMENAME_preprocess_node(&$variables) {    if ($variables['node']->field_image->entity) {       $variables['image_url'] = $url = entity_load('image_style', 'medium')->buildUrl($variables['node']->field_image->entity->getFileUri());   } }   

可以改善。我正在检查图像字段,并使用图像样式加载其URL。

然后在我的节点中 - page.html.twig文件我有这个:

  {% if image_url is not empty %}     <div class="featured-thumb">         <img src="{{ image_url }}"/>     </div> {% endif %}  <div>{{ content.body|without('field_image') }}</div>   

再次,可以使用一些改进。谢谢

 

I use this code in my .theme file:

function THEMENAME_preprocess_node(&$variables) {    if ($variables['node']->field_image->entity) {       $variables['image_url'] = $url = entity_load('image_style', 'medium')->buildUrl($variables['node']->field_image->entity->getFileUri());   } } 

It could be improved. I'm checking for the image field, and loading its url with an image style.

Then in my node--page.html.twig file I have this:

{% if image_url is not empty %}     <div class="featured-thumb">         <img src="{{ image_url }}"/>     </div> {% endif %}  <div>{{ content.body|without('field_image') }}</div> 

Again, that could use some improvement. thanks

 
 
   
       
1
 
vote

我会做另一种方式。在节点预处理功能中:

  use DrupalimageEntityImageStyle; // Don't forget this use.  function THEMENAME_preprocess_node__NODETYPE(&$variables){     $node = $variables['node'];      if(isset($node->get('field_image')->entity)){         $image_style = 'large'; // Or whatever your image style's machine name is.         $style = ImageStyle::load($style);         $variables['image'] = $style->buildUrl($node->get('field_image')->entity->getFileUri()); // Generates file url.     } }   
然后,在您的模板(节点 - nodetype.html.twig)中,只需渲染图像的方式:
  {% if image %}     <img src="{{ image }}" /> {% endif %}   

虽然,如果您必须渲染大量图像,我建议您在每个图像上循环之前在数组中加载样式。我在说,因为我遇到了严重的负载时间问题,因为我必须加载超过300个图像和每个图像,我以前单独加载样式,而不是以前加载它们,这是一个例子,相同的基础:

  use DrupalimageEntityImageStyle; // Don't forget this use.  function THEMENAME_preprocess_node__NODETYPE(&$variables){     $node = $variables['node'];      if(isset(node->get('field_images')[0]->entity)){ // Notice how, this time, I check if the FIRST image is set (if it's true, then u'll allow the loop for at least 1 element)         $images_styles = [             'large' => ImageStyle::load('large'),             'thumbnail' => ImageStyle::load('thumbnail')         ];         $count = 0;          foreach($node->get('field_images') as $image){             $variables['images'][$count]['large'] = $images_styles['large']->buildUrl($image->getFileUri());             $variables['images'][$count]['thumbnail'] = $images_styles['thumbnail']->buildUrl($image->getFileUri());             $count++;         }     } }   
然后再说,在您的模板(node - nodetype.html.twig)中,只需渲染图像的方式:
  {% if images %}     <ul>         {% for image in images %}             <li>                 <img src="{{ image.large }}" /> // Large image url.                 <img src="{{ image.thumbnail }}" /> // Thumbnail image url.             </li>            {% endfor %}     </ul> {% endif %}   

我还没有真正测试过它,我从我的头上取出所有这一切,所以它可能包含错误,随时警告我,所以我会纠正这个: - )。

 

I'd do it another way. In your node preprocess function :

use Drupal\image\Entity\ImageStyle; // Don't forget this use.  function THEMENAME_preprocess_node__NODETYPE(&$variables){     $node = $variables['node'];      if(isset($node->get('field_image')->entity)){         $image_style = 'large'; // Or whatever your image style's machine name is.         $style = ImageStyle::load($style);         $variables['image'] = $style->buildUrl($node->get('field_image')->entity->getFileUri()); // Generates file url.     } } 

Then, in your template (node--NODETYPE.html.twig), just render the image that way :

{% if image %}     <img src="{{ image }}" /> {% endif %} 

Although, if you ever have to render a big amount of images, I'd advise you to load the styles in an array before you loop on each images. I'm saying that because I've ran into serious load time problems because I had to load over 300 images and for each image, I was loading the style individually instead of loading them all before, here's an example, same base as above :

use Drupal\image\Entity\ImageStyle; // Don't forget this use.  function THEMENAME_preprocess_node__NODETYPE(&$variables){     $node = $variables['node'];      if(isset(node->get('field_images')[0]->entity)){ // Notice how, this time, I check if the FIRST image is set (if it's true, then u'll allow the loop for at least 1 element)         $images_styles = [             'large' => ImageStyle::load('large'),             'thumbnail' => ImageStyle::load('thumbnail')         ];         $count = 0;          foreach($node->get('field_images') as $image){             $variables['images'][$count]['large'] = $images_styles['large']->buildUrl($image->getFileUri());             $variables['images'][$count]['thumbnail'] = $images_styles['thumbnail']->buildUrl($image->getFileUri());             $count++;         }     } } 

Then again, in your template (node--NODETYPE.html.twig), just render the images that way :

{% if images %}     <ul>         {% for image in images %}             <li>                 <img src="{{ image.large }}" /> // Large image url.                 <img src="{{ image.thumbnail }}" /> // Thumbnail image url.             </li>            {% endfor %}     </ul> {% endif %} 

I haven't really tested it and I'm getting all this out of my head so it might contain errors, feel free to warn me so I'll correct this :-).

 
 
0
 
vote

花了两天后,我发现了一些答案到了我的类似代码。包含和排除某些字段。

  {% set classes = [ 'block', 'block-' ~ configuration.provider|clean_class, 'block-' ~ plugin_id|clean_class, 'cover-image', ] %}  {% set background_image = file_url(content.field_banner_image['#items'].entity.uri.value) %}  <div{{ attributes.addClass(classes) }} style="background-image:  url({{background_image}})">  <div class="block-inner"> {{ title_prefix }} {% if label %} <h2{{ title_attributes }}>{{ label }}</h2> {% endif %} {{ title_suffix }} {% block content %} {{ content.field_media_image }} <div class="summary"> {{ content|without('field_banner_image') }} </div> {% endblock %} </div> </div>   

主题块中的姓名 - Bundle - Banner-Block.html.twig此代码用于带图像的自定义块。

简单文件的另一个例子。没有吝啬整个代码,而是只有必要。

  <a href="{{file_url(node.field_attachment1.entity.uri.value)  }}" ><h3>  {{content.field_short_information}} </h3></a>   

节点节点的代码片段 - all_notice.html.twig。所有目前在Drupal 8.8.3的东西

 

After spending two days I found some answer to my similar code. With including and excluding some fields.

{% set classes = [ 'block', 'block-' ~ configuration.provider|clean_class, 'block-' ~ plugin_id|clean_class, 'cover-image', ] %}  {% set background_image = file_url(content.field_banner_image['#items'].entity.uri.value) %}  <div{{ attributes.addClass(classes) }} style="background-image:  url({{background_image}})">  <div class="block-inner"> {{ title_prefix }} {% if label %} <h2{{ title_attributes }}>{{ label }}</h2> {% endif %} {{ title_suffix }} {% block content %} {{ content.field_media_image }} <div class="summary"> {{ content|without('field_banner_image') }} </div> {% endblock %} </div> </div> 

fine name in theme block--bundle--banner-block.html.twig This code is for custom block with images.

Another Example for simple file. not Pesting whole code, but only essential.

<a href="{{file_url(node.field_attachment1.entity.uri.value)  }}" ><h3>  {{content.field_short_information}} </h3></a> 

This code snippets for node node--all_notice.html.twig. All things currently working in drupal 8.8.3

 
 
-1
 
vote

我使用了使用背景图像模块当用例允许它。当我需要自定义的DOM结构时,我使用这些代码选项之一。

 

I've had some success using the Background Image Module when the use case allows for it. I use one of these code options when I need a customized DOM structure.

 
 
35
 
vote
vote
最佳答案
 

变量 node 仅在节点模板(和页面模板中,如果URL包含节点)。现在,如果要在现场模板中访问节点字段,则必须在不同的位置查看:

field.html.twig:

  {{ file_url(element['#object'].field_image.0.entity.uri.value) }}   

element['#object'] 是字段模板中的父实体,您可以从此实体访问任何字段(在您的情况下节点)。

如果要从实际字段访问原始值,最好遵循字段枝条的逻辑并直接从现场项目对象 #item :< / p>

  {% for item in items %}   {{ file_url(item.content['#item'].entity.uri.value) }} {% endfor %}   

编辑:获取图像样式的URL

安装模块 twig调整,您可以使用URI获取图像的URL风格:

  EntityMetadataWrapper0  

 

The variable node is only preloaded in the node template (and the page template, if the url contains the node). Now if you want to access node fields in a field template you have to look in a different place:

field.html.twig:

{{ file_url(element['#object'].field_image.0.entity.uri.value) }} 

element['#object'] is the parent entity in a field template and you can access any field from this entity (in your case the node).

If you want to access raw values from the actual field, it's better to follow the logic of the field twig and access the value inside of the items loop directly from the field item object #item:

{% for item in items %}   {{ file_url(item.content['#item'].entity.uri.value) }} {% endfor %} 

Edit: Get the url of an image style

Install the module Twig Tweak and you can use the uri to get the url of an image style:

{% for item in items %}   {{ item.content['#item'].entity.uri.value | image_style('thumbnail') }} {% endfor %} 
 
 
       
               
29
 
vote

只是提到,如果您想要在其中一个新的自定义块中执行此操作:

  EntityMetadataWrapper1  
 

Just to mention that if you want to do the same in one of the new custom blocks this works:

{{ file_url(content.field_image['#items'].entity.uri.value) }} 
 
 
               
                               
3
 
vote

我在我的.theme文件中使用此代码:

  function THEMENAME_preprocess_node(&$variables) {    if ($variables['node']->field_image->entity) {       $variables['image_url'] = $url = entity_load('image_style', 'medium')->buildUrl($variables['node']->field_image->entity->getFileUri());   } }   

可以改善。我正在检查图像字段,并使用图像样式加载其URL。

然后在我的节点中 - page.html.twig文件我有这个:

  {% if image_url is not empty %}     <div class="featured-thumb">         <img src="{{ image_url }}"/>     </div> {% endif %}  <div>{{ content.body|without('field_image') }}</div>   

再次,可以使用一些改进。谢谢

 

I use this code in my .theme file:

function THEMENAME_preprocess_node(&$variables) {    if ($variables['node']->field_image->entity) {       $variables['image_url'] = $url = entity_load('image_style', 'medium')->buildUrl($variables['node']->field_image->entity->getFileUri());   } } 

It could be improved. I'm checking for the image field, and loading its url with an image style.

Then in my node--page.html.twig file I have this:

{% if image_url is not empty %}     <div class="featured-thumb">         <img src="{{ image_url }}"/>     </div> {% endif %}  <div>{{ content.body|without('field_image') }}</div> 

Again, that could use some improvement. thanks

 
 
   
       
1
 
vote

我会做另一种方式。在节点预处理功能中:

  use DrupalimageEntityImageStyle; // Don't forget this use.  function THEMENAME_preprocess_node__NODETYPE(&$variables){     $node = $variables['node'];      if(isset($node->get('field_image')->entity)){         $image_style = 'large'; // Or whatever your image style's machine name is.         $style = ImageStyle::load($style);         $variables['image'] = $style->buildUrl($node->get('field_image')->entity->getFileUri()); // Generates file url.     } }   
然后,在您的模板(节点 - nodetype.html.twig)中,只需渲染图像的方式:
  {% if image %}     <img src="{{ image }}" /> {% endif %}   

虽然,如果您必须渲染大量图像,我建议您在每个图像上循环之前在数组中加载样式。我在说,因为我遇到了严重的负载时间问题,因为我必须加载超过300个图像和每个图像,我以前单独加载样式,而不是以前加载它们,这是一个例子,相同的基础:

  use DrupalimageEntityImageStyle; // Don't forget this use.  function THEMENAME_preprocess_node__NODETYPE(&$variables){     $node = $variables['node'];      if(isset(node->get('field_images')[0]->entity)){ // Notice how, this time, I check if the FIRST image is set (if it's true, then u'll allow the loop for at least 1 element)         $images_styles = [             'large' => ImageStyle::load('large'),             'thumbnail' => ImageStyle::load('thumbnail')         ];         $count = 0;          foreach($node->get('field_images') as $image){             $variables['images'][$count]['large'] = $images_styles['large']->buildUrl($image->getFileUri());             $variables['images'][$count]['thumbnail'] = $images_styles['thumbnail']->buildUrl($image->getFileUri());             $count++;         }     } }   
然后再说,在您的模板(node - nodetype.html.twig)中,只需渲染图像的方式:
  {% if images %}     <ul>         {% for image in images %}             <li>                 <img src="{{ image.large }}" /> // Large image url.                 <img src="{{ image.thumbnail }}" /> // Thumbnail image url.             </li>            {% endfor %}     </ul> {% endif %}   

我还没有真正测试过它,我从我的头上取出所有这一切,所以它可能包含错误,随时警告我,所以我会纠正这个: - )。

 

I'd do it another way. In your node preprocess function :

use Drupal\image\Entity\ImageStyle; // Don't forget this use.  function THEMENAME_preprocess_node__NODETYPE(&$variables){     $node = $variables['node'];      if(isset($node->get('field_image')->entity)){         $image_style = 'large'; // Or whatever your image style's machine name is.         $style = ImageStyle::load($style);         $variables['image'] = $style->buildUrl($node->get('field_image')->entity->getFileUri()); // Generates file url.     } } 

Then, in your template (node--NODETYPE.html.twig), just render the image that way :

{% if image %}     <img src="{{ image }}" /> {% endif %} 

Although, if you ever have to render a big amount of images, I'd advise you to load the styles in an array before you loop on each images. I'm saying that because I've ran into serious load time problems because I had to load over 300 images and for each image, I was loading the style individually instead of loading them all before, here's an example, same base as above :

use Drupal\image\Entity\ImageStyle; // Don't forget this use.  function THEMENAME_preprocess_node__NODETYPE(&$variables){     $node = $variables['node'];      if(isset(node->get('field_images')[0]->entity)){ // Notice how, this time, I check if the FIRST image is set (if it's true, then u'll allow the loop for at least 1 element)         $images_styles = [             'large' => ImageStyle::load('large'),             'thumbnail' => ImageStyle::load('thumbnail')         ];         $count = 0;          foreach($node->get('field_images') as $image){             $variables['images'][$count]['large'] = $images_styles['large']->buildUrl($image->getFileUri());             $variables['images'][$count]['thumbnail'] = $images_styles['thumbnail']->buildUrl($image->getFileUri());             $count++;         }     } } 

Then again, in your template (node--NODETYPE.html.twig), just render the images that way :

{% if images %}     <ul>         {% for image in images %}             <li>                 <img src="{{ image.large }}" /> // Large image url.                 <img src="{{ image.thumbnail }}" /> // Thumbnail image url.             </li>            {% endfor %}     </ul> {% endif %} 

I haven't really tested it and I'm getting all this out of my head so it might contain errors, feel free to warn me so I'll correct this :-).

 
 
0
 
vote

花了两天后,我发现了一些答案到了我的类似代码。包含和排除某些字段。

  {% set classes = [ 'block', 'block-' ~ configuration.provider|clean_class, 'block-' ~ plugin_id|clean_class, 'cover-image', ] %}  {% set background_image = file_url(content.field_banner_image['#items'].entity.uri.value) %}  <div{{ attributes.addClass(classes) }} style="background-image:  url({{background_image}})">  <div class="block-inner"> {{ title_prefix }} {% if label %} <h2{{ title_attributes }}>{{ label }}</h2> {% endif %} {{ title_suffix }} {% block content %} {{ content.field_media_image }} <div class="summary"> {{ content|without('field_banner_image') }} </div> {% endblock %} </div> </div>   

主题块中的姓名 - Bundle - Banner-Block.html.twig此代码用于带图像的自定义块。

简单文件的另一个例子。没有吝啬整个代码,而是只有必要。

  <a href="{{file_url(node.field_attachment1.entity.uri.value)  }}" ><h3>  {{content.field_short_information}} </h3></a>   

节点节点的代码片段 - all_notice.html.twig。所有目前在Drupal 8.8.3的东西

 

After spending two days I found some answer to my similar code. With including and excluding some fields.

{% set classes = [ 'block', 'block-' ~ configuration.provider|clean_class, 'block-' ~ plugin_id|clean_class, 'cover-image', ] %}  {% set background_image = file_url(content.field_banner_image['#items'].entity.uri.value) %}  <div{{ attributes.addClass(classes) }} style="background-image:  url({{background_image}})">  <div class="block-inner"> {{ title_prefix }} {% if label %} <h2{{ title_attributes }}>{{ label }}</h2> {% endif %} {{ title_suffix }} {% block content %} {{ content.field_media_image }} <div class="summary"> {{ content|without('field_banner_image') }} </div> {% endblock %} </div> </div> 

fine name in theme block--bundle--banner-block.html.twig This code is for custom block with images.

Another Example for simple file. not Pesting whole code, but only essential.

<a href="{{file_url(node.field_attachment1.entity.uri.value)  }}" ><h3>  {{content.field_short_information}} </h3></a> 

This code snippets for node node--all_notice.html.twig. All things currently working in drupal 8.8.3

 
 
-1
 
vote

我使用了使用背景图像模块当用例允许它。当我需要自定义的DOM结构时,我使用这些代码选项之一。

 

I've had some success using the Background Image Module when the use case allows for it. I use one of these code options when I need a customized DOM structure.

 
 

相关问题

2  打印五星级评分和评论  ( Print five star ratings and reviews ) 
我正在使用 fivestar 评级在自定义打印中。查看图像: 我正在尝试按如下方式打印fivestar: $your_average = $variables['result']['node']->field_rating['und'][0]['average']; $your_maximum = "100...

0  严格的警告:只有变量应该通过开放式餐厅的参考通过[复制]  ( Strict warning only variables should be passed by reference in open restaurant ) 
这个问题已经在这里有一个答案: 严格警告:只有变量应该通过引用传递 (1答) ...

4  有没有导出块布局设置的方法?  ( Is there way to export block layout settings ) 
我创建了自定义主题,我想知道是否有导出我的块布局设置(每个块的位置和顺序)。这种方式更容易在不同的网站上应用我的主题。 我正在使用功能模块,以跟踪我的自定义块和块类型。 ...

15  如何为特定模块禁用枝条和块缓存?  ( How do i disable twig and block cache for a specific module ) 
我正在使用Drupal 8中的模块,该模块从外部REST API检索时间敏感数据。处理数据并转发到块。最终数据被发送到像这样的枝条模板: ... public function build() { $build = []; $build['ticker_block'] = [ '#theme'...

2  转储(),kint()和print_r()不在.theme文件中工作  ( Dump kint print r are not working in theme file ) 
我用devel模块使用drupal 8。我想在视图字段中动态地更改一些值。所以我尝试使用主题_preprocess_views_view_fields()。当我尝试使用print_r(),kint()&amp打印变量时;转储(),没有一个打印值。 /** * Implement theme_preprocess...

0  如何将表单的隐藏字段移动到其他字段之上  ( How to move hidden fields of a form above other fields ) 
当在drupal中呈现表单元素时,在表单标签中添加了一些隐藏字段,如波纹管: <form action="/example/unsubscribe" method="post" id="exampleform-unsubscribe" accept-charset="UTF-8"> <div> <di...

6  将属性添加到HTML和身体  ( Add attribute to html and body ) 
我需要将 class="no-trans" 添加到正文,还要编辑HTML标记。 如何编辑 {{ html_attributes }} 和 {{ body_attributes }} ? 我的html.html.twig <!DOCTYPE html> <html{{ html_attributes }}> ...

3  如何创建首页?  ( How do i create a front page ) 
我正在D7开发新网站,我已经安装了 bootstrap主题 。 所以,现在我想为我的网站创建主页/前页,并为我创建了一个基本页面,但我无法在该基本页面中添加CSS和JS。 我应该使用哪种方法来在Drupal 7中创建首页? ...

1  Bootstrap:响应表与WYSIWYG文本格式[已关闭]  ( Bootstrap responsive tables with wysiwyg text format ) 
关闭。这个问题需要更多聚焦。它目前不接受答案。 想要改进这个问题?更新问题,以便仅通过编辑此帖。 关闭 5年前。 ...

0  访问用户配置文件时出现问题  ( Problem when visiting users profiles ) 
在我的网站上,用户可以连接,查看他们的配置文件,更新其配置文件和访问其他用户配置文件 对于每个用户,我创建了一个配置文件页面 user-profile.tpl.php 但是当我访问其他用户帐户时,我有些麻烦。 例如,在我的帐户配置文件页面中,有一个链接将我重定向到编辑页面。 我写了这个代码来显示编辑链接: ...

1  将Bootstrap主题添加到一个区域  ( Adding the bootstrap theme to one region ) 
我有复杂的网站,具有自定义主题。我正在考虑实施引导主题,但仅适用于一个地区。 这可能吗?有没有不同的方法来解决这个问题? 非常感谢:) ...

8  从枝条中获取带有样式URL的图像  ( Get an image with style url from an uri in twig ) 
所以感谢 4k4 我终于管理到通过获取我的原始图像URI item.content['#item'].entity.uri.value 和 {{ file_url(item.content['#item'].entity.uri.value) }} 我会得到原始文件的URL。 我通过具有图像样式...

2  作者字段到内容类型模板  ( Author fields into a content type template ) 
我试图将作者加载到节点中的一些信息 - Stretty.html.twig 。所以我可以提供一些信息,如生物,社交媒体等。 类似于这个... 我可以轻松获取 author_name 和 author_picture ,因为这两个由模板给出。我在 admin/config/people/accounts/fi...

1  如何在Bartik主题中移动“主导航”?  ( How to move the main navigation in the bartik theme ) 
在Drupal 8中,通过Bartik主题,我想将"主菜单" 区域的"主要导航" 选项卡放在右上方的"网站品牌" 块旁边。 如果我只是将"主导航" 移动到标题区域,则选项卡丢失。 我想保留标签。 如何做到? ...

1  使用模块编辑用户配置文件模板  ( Edit user profile template with module ) 
如何在Drupal 7中编辑用户配置文件模板? 我在项目中创建了一个名为sporthron的模块。 sporthron.module包含: /** * Implements hook_theme(). */ function sporthron_theme($existing, $type, $theme,...

0  是否可以从使用呈现实体格式的字段中删除类?  ( Is it possible to remove classes from a field that uses the rendered entity form ) 
我有一个由显示套件处理的实体参考字段。即使将字段模板设置为专家,我也无法完全剥离默认类。标记仍然有一个如此: <span class="field-content"> <div about="/products/chicken-breast-tenderloins" typeof="sioc:Item foa...

0  新地区或module_invoke?  ( New region or module invoke ) 
我正在开发一个简单的网站,并希望尽可能简单地保持一切,而没有任何不必要的性能丢失或redundat代码。设计非常静止,因此不需要大量的地区。 lateslty我只有一个区域和2个模板 - 一个用于前页,第二页,这就是我到目前为止所需的一切。 但是语言切换器模块生成的新块,显示用于交换语言的选择输入。通过创建新区域并将...

1  在块内主题  ( Theming inside blocks ) 
我不知道Drupal 8中的区域内部的主题进程。我通过将{{page.xxx}}放在枝条文件中(在yml文件中的区域声明)中来到主题区域。但是示例我具有包含2个块的"内容" 区域:页面标题和主页内容。如何仅对斜纹文件中的页面标题或主页数内容块进行主题,也可以使用块内的字段(文本,标题等)。最受欢迎的任何帮助。 ...

16  Clish_Class和Clean_id工作如何?  ( How do clean class and clean id work ) 
我是drupal 8和twig语法的新手。我无法理解 clean_class 过滤器如何在 99887661 中使用。什么是 clean_class ?我在Page.html.twig文件中添加了以下代码。 {% set classes = [ 'region', 'region-' ~ re...

0  用户配置文件页面中的显示节点  ( Display node in user profile page ) 
我创建了一个名为 successful story 的内容类型。 在用户配置文件页面 user-profile.tpl.php ,我已插入一个链接以创建 successful story <?php print l(t('Add a successful story'), "node/add/successf...




© 2021 it.wenda123.org All Rights Reserved. 问答之家 版权所有


Licensed under cc by-sa 3.0 with attribution required.