我想为我通过转到结构/块布局/类型/添加自定义块类型创建的自定义块类型创建模板。我创建的类型称为菜单。如何从这里创建此自定义块类型的模板?我对 Drupal 不太熟悉,所以任何帮助将不胜感激。
我正在尝试从 drupal 获取某种类型的所有节点。我尝试了很多方法来实现这一目标,但也许由于我缺乏 Drupal 自定义模块编程经验,我无法实现我的愿望。我在网上找到的最接近的方法是:
$nids = \Drupal::entityQuery('node')->condition('type','news')->execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
Run Code Online (Sandbox Code Playgroud)
这看起来简单又直接。但是,这就是输出!
{
"59": {
"in_preview": null
},
"61": {
"in_preview": null
}
}
有人可以帮忙吗,出了什么问题?这是正确的方法吗?
我想获取节点,然后搜索其中的每一个(我正在制作某种搜索引擎),所以我期望某种对象,然后我可以从中提取标题、正文等。这是正确的方法吗?
我在(父)段落中有一个实体引用字段,它引用多个子段落。
是否可以访问子级(引用段落)树枝模板中引用段落的字段值?
实际上,我只是想计算引用项目的树枝模板本身之一内的引用项目总数。所以如果你愿意的话,我想计算它的兄弟姐妹+1。
我知道我可以在模块中对此进行预处理,但我想知道这在树枝中是否可行。
我最近在 Windows Server 上安装了 Drupal,安装时没有出现任何错误。有针对 OPCaching 的警告。我也不认为它会影响它,但我使用了 SQLite。
安装后,默认页面加载时没有 CSS。有谁知道为什么会发生这种情况或如何解决它?
我想要实现的是插件的简单配置.我需要实体参考字段,用户可以使用自动完成字段将某些产品添加到配置中.我试图使用Config Entity,但它看起来和Form Api看起来一样,我不能在那里使用实体字段.我等不及要你回复了.
我是Drupal的新手,我非常喜欢它.我是靠自己学习但是现在我遇到了问题.
我创建了一个自定义块,显示标题和链接列表.因此,该块中的唯一字段是类型链接.这是我的页脚区域的一个块.因此,当用户点击时,它会在新标签页中打开一个新网站.
我想改变这个块类型的html输出,所以我拿出了这个主题建议:field - block-content - field-links - footer-links.html.twig
我的问题是如何为每个<a>标签添加一个类?
我尝试使用模块'link class'.它有效.它只在安装模块之前读取css中已存在的类.它不会读取安装模块后创建的新类.我尝试了不同的东西,多次清理缓存但很奇怪.必须有一种更好的方法来添加没有模块的类.
任何人都可以帮助我并向我展示在我的<a>标签中添加课程的最佳方法吗?
谢谢 :)
这是默认模板
{% if label_hidden %}
{% if multiple %}
<div{{ attributes }}>
{% for item in items %}
<div{{ item.attributes }}>{{ item.content }}</div>
{% endfor %}
</div>
{% else %}
{% for item in items %}
{{ item.content }} -------------> add class here
{% endfor %}
{% endif %}
{% else %}
<div{{ attributes }}>
<div{{ title_attributes }}>{{ label }}</div>
{% …Run Code Online (Sandbox Code Playgroud) 使用“字段收集”模块时出现此错误:
Twig_Sandbox_SecurityError: Calling "uri" method on a "Drupal\field_collection\Entity\FieldCollectionItem" object is not allowed in "themes/communitylife/templates/content/node.html.twig" at line 83. in Drupal\Core\Template\TwigSandboxPolicy->checkMethodAllowed() (line 99 of core/lib/Drupal/Core/Template/TwigSandboxPolicy.php).
Run Code Online (Sandbox Code Playgroud)
导致问题的代码是以下代码:
<div class=" title-col col-md-7">
<a href="{{file_url(node.field_pressemappe_bildmaterial[key].getFieldCollectionItem().field_presse_bild_file.entity.uri.value)}}" target="_blank"> <strong> {{node.field_pressemappe_bildmaterial[key].getFieldCollectionItem().field_presse_bild_description.value}}
<span class="file-type"> ({{node.field_pressemappe_bildmaterial[key].getFieldCollectionItem().field_presse_bild_file.entity.uri.value | slice(-3) }} </span>, <span class="file-size"> {{node.field_pressemappe_bildmaterial[key].getFieldCollectionItem().field_presse_bild_file.entity.size }}) </span>
</strong></a>
</div>
Run Code Online (Sandbox Code Playgroud)
解决此问题的最佳方法是什么?通过在沙箱策略的允许方法中添加(uri)来实现?如果是,那我该怎么做?
我在树枝文档中阅读到可以执行以下操作:
$policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions);
Run Code Online (Sandbox Code Playgroud)
但我不知道如何或在何处放置此代码。
提前致谢
在Drupal 8中安装不在packagist上的第三方库的最佳方法是什么?
例如,我有Color Field模块,它可以使用jQuery Simple Color Picker库来提供更好的用户体验.
最明显的解决方案是手动添加库,但这不是真正可维护的.
我的第二个想法是将git存储库添加到我的composer.json中,如下所示,但它不起作用,因为目标存储库没有composer.json文件.
"repositories": [
{
"name": "jquery-simple-color",
"type": "git",
"url": "https://github.com/recurser/jquery-simple-color.git"
}
],
"require": {
"jquery-simple-color/": "1.2.1"
}
Run Code Online (Sandbox Code Playgroud)
我应该只是分叉git存储库并在那里添加composer.json文件吗?
我在Drupal 8中有多个值图像字段,我想在Controller中准备值以在树枝模板中输出。
对于单个值字段,它很简单(好吧,如果我们可以称呼荒谬而又复杂的“让OOP尽其所能,尽管它毫无用处”, Drupal 8种方式都很简单):
$nids = \Drupal::entityQuery('node')->condition('type', 'zbornik_a_foto')->execute();
$nodes = Node::loadMultiple($nids);
$data = array();
foreach ($nodes as $node) {
$data[] = array(
'rocnik' => $node->get('field_rok')->getValue(),
'miesto' => $node->get('field_miesto_konania')->getValue(),
'fotografie' => $node->get('field_zbornik')->getValue(),
'foto' => $node->get('field_fotografie')->getValue(),
);
}
return array(
'#theme' => 'riadky_zazili',
'#data' => $data,
'#title' => 'Zažili sme',
);
Run Code Online (Sandbox Code Playgroud)
但是,field_fotografie值是多个值字段,我想在$data数组中获取所有图像的URI 。有人知道吗?理想情况下,少于10行的无用的OOP跳线。谢谢。
我正在尝试在Drupal 8中安装商务模块,但是出现错误“找不到BC math PHP扩展名”。
我已经搜索了此问题,并尝试了其他操作,例如通过添加'bcmath.scale = 2'来编辑PHP.ini,但是我仍然收到错误消息。
任何帮助,将不胜感激,谢谢。