Drupal 8 - 创建手风琴场
Drupal 8 - creating an accordion field
在 Drupal 8 中 -- 我想修改基本页面内容类型以支持 "accordion field type"
我已经看到列表字段类型 - 可以有无限字段 - 但我正在寻找一个解决方案可以具有 - header/body - 类型特征。
没有模块可以为您处理这个问题,解决方案是在您的内容类型中创建无限制的实体引用,它必须有两个字段,如您所愿,Title
和 Body
,并且要将其转换为手风琴,您应该自定义新的实体字段主题并在那里实施手风琴。
另一个解决方案是,通过https://www.drupal.org/project/views_bootstrap which support accordion or https://www.drupal.org/project/faqfield模块处理它:
Features:
Configurable default text formats
Configurable answer widget
Types: Normal textareas, textfields and formatable textareas
Formatable textareas for any Wysiwyg editor
Configurable number of rows for textarea widget
Field formatters
jQuery Accordion UI
Simple themeable text
Definition list (HTML <dl>)
Anchor link list
Accordion display options
Choose first active question
Collapse open questions
Event to open/collapse questions (eg. mouseover, click)
Drupal 核心可以很好地满足您的需求——因为它可以满足一些常见的 UI 要求,例如手风琴。您可以很容易地重用现有的核心资产,如果这条路线满足您的要求,您将获得一些令人钦佩的维护好处,因为核心比任何给定的 contrib 模块更受 Drupal 社区的关注。
核心可以提供帮助的两种方式:
- 您可以调用核心附带的 jQuery UI Accordion。
- 您可以在 Toolbar Menu 上设计一些东西,它“构建一个嵌套的手风琴小部件”。
如果第一个选项看起来很有希望,Examples module gives an example for how to use the core jQuery assets, specifically focusing on the accordion UI. (That's called serendipity incarnate!) Here's the javascript code:
(function ($) {
'use strict';
$(function () {
$('#accordion').accordion();
});
})(jQuery);
这里是 module code:
function js_example_theme() {
return [
'js_example_accordion' => [
'template' => 'accordion',
'variables' => ['title' => NULL],
],
];
}
再简单不过了。请注意,如果自定义模块不如 adding the feature in your theme 适合,您可以选择其中一个。
在 Drupal 8 中 -- 我想修改基本页面内容类型以支持 "accordion field type"
我已经看到列表字段类型 - 可以有无限字段 - 但我正在寻找一个解决方案可以具有 - header/body - 类型特征。
没有模块可以为您处理这个问题,解决方案是在您的内容类型中创建无限制的实体引用,它必须有两个字段,如您所愿,Title
和 Body
,并且要将其转换为手风琴,您应该自定义新的实体字段主题并在那里实施手风琴。
另一个解决方案是,通过https://www.drupal.org/project/views_bootstrap which support accordion or https://www.drupal.org/project/faqfield模块处理它:
Features:
Configurable default text formats
Configurable answer widget
Types: Normal textareas, textfields and formatable textareas
Formatable textareas for any Wysiwyg editor
Configurable number of rows for textarea widget
Field formatters
jQuery Accordion UI
Simple themeable text
Definition list (HTML <dl>)
Anchor link list
Accordion display options
Choose first active question
Collapse open questions
Event to open/collapse questions (eg. mouseover, click)
Drupal 核心可以很好地满足您的需求——因为它可以满足一些常见的 UI 要求,例如手风琴。您可以很容易地重用现有的核心资产,如果这条路线满足您的要求,您将获得一些令人钦佩的维护好处,因为核心比任何给定的 contrib 模块更受 Drupal 社区的关注。
核心可以提供帮助的两种方式:
- 您可以调用核心附带的 jQuery UI Accordion。
- 您可以在 Toolbar Menu 上设计一些东西,它“构建一个嵌套的手风琴小部件”。
如果第一个选项看起来很有希望,Examples module gives an example for how to use the core jQuery assets, specifically focusing on the accordion UI. (That's called serendipity incarnate!) Here's the javascript code:
(function ($) {
'use strict';
$(function () {
$('#accordion').accordion();
});
})(jQuery);
这里是 module code:
function js_example_theme() {
return [
'js_example_accordion' => [
'template' => 'accordion',
'variables' => ['title' => NULL],
],
];
}
再简单不过了。请注意,如果自定义模块不如 adding the feature in your theme 适合,您可以选择其中一个。