我很难理解hook_theme()的作用.
我的理解是它与可以覆盖模板有关.
我在看:
$theme_hooks = array(
'poll_vote' => array(
'template' => 'poll-vote',
'render element' => 'form',
),
'poll_choices' => array(
'render element' => 'form',
),
'poll_results' => array(
'template' => 'poll-results',
'variables' => array('raw_title' => NULL, 'results' => NULL, 'votes' => NULL, 'raw_links' => NULL, 'block' => NULL, 'nid' => NULL, 'vote' => NULL),
),
'poll_bar' => array(
'template' => 'poll-bar',
'variables' => array('title' => NULL, 'votes' => NULL, 'total_votes' => NULL, 'vote' => NULL, 'block' => NULL), …Run Code Online (Sandbox Code Playgroud) 我在Drupal 7 template.php文件中有以下代码:
function mytheme_preprocess_views_view__videos__videos(&$vars) {
drupal_add_css(drupal_get_path('theme', 'mytheme') . "/css/qwembed-jquery-1.0.css");
drupal_add_js(drupal_get_path('theme', 'mytheme').'/js/jquery.swfobject.1-1-1.min.js', array('type' => 'file', 'scope' => 'footer'));
drupal_add_js(drupal_get_path('theme', 'mytheme').'/js/qwembed-jquery-1.0.js', array('type' => 'file', 'scope' => 'footer'));
}
Run Code Online (Sandbox Code Playgroud)
我只需要在显示此视图时加载这些css和js文件.
视图显示名称为:Videos
视图机器名称为:videos
和覆盖文件是:
views-view--videos--videos.tpl.php
views-view-unformatted--videos--videos.tpl.php
views-view-fields--videos--videos.tpl.php
Run Code Online (Sandbox Code Playgroud)
任何想法为什么这不起作用?
我可以在Drupal模板文件中使用令牌替换吗?我正在尝试这个:
$author_uid = "[node:author:uid]";
$nid = "[node:nid]";
Run Code Online (Sandbox Code Playgroud)
但它不起作用.如何在node.tpl.php模板中正确使用令牌替换?
我试图通过使用插入标题中的Javascript文件的引用drupal_add_js().我将此行放在template.php中的模板预处理函数中.代码根本不起作用的结果:输出中没有脚本链接.谁能告诉我我做错了什么?
function phptemplate_preprocess_page(&$vars) {
$url = drupal_get_path("theme","mysite");
drupal_add_js($url."/jquery.js");
drupal_add_js($url."/drupal.js");
.....
Run Code Online (Sandbox Code Playgroud) 在Drupal 7中
views-view-grid--super-gallery--block.tpl.php在视图编辑器中使用预览我可以看到模板修改的输出.好
<?php print views_embed_view("super_gallery", "default", $gallery_arguments); ?>
在另一个模板中使用以显示*super_gallery*视图,它显示输出而不进行更改.坏
我如何使用模板views_embed_view?
编辑1 也尝试:
$view = views_get_view("super_gallery");
print $view->preview("default", $gallery_arguments);
Run Code Online (Sandbox Code Playgroud)
和
$view = views_get_view("super_gallery");
print $view->execute_display("default", $gallery_arguments);
Run Code Online (Sandbox Code Playgroud)
没有改变
我想从 core/modules/search/src/Controller\SearchController.php 的第 119 行删除搜索页面中添加的搜索结果字符串。
if (count($results)) {
$build['search_results_title'] = array(
'#markup' => '<h2>' . $this->t('Search results') . '</h2>',
);
}
Run Code Online (Sandbox Code Playgroud)
我可以使用搜索表单上的 preprocess_form 函数和搜索结果上的 preprocess_search_result 更改上面的搜索表单和结果列表。
是否有我错过的预处理功能,或者我可以使用自定义模板文件吗?
我已成功使用预处理页面挂钩,例如:
function mytheme_preprocess_page__node_front(&$variables) {
...
}
Run Code Online (Sandbox Code Playgroud)
和
function mytheme_preprocess_page__node_12(&$variables) {
...
}
Run Code Online (Sandbox Code Playgroud)
它与分别名为page - front.html.twig和page - 12.html.twig的自定义模板相关联.
我正在尝试为名为Video的内容类型实现相同的挂钩和模板配对.我的理解是,我的示例是针对特定页面的自定义模板,而我的目标是整个内容类型的自定义模板,但我得到了一个名为node的自定义模板 - video.html.twig可用作所有视频页面的模板.但是,当我尝试根据此模板名称编写一个钩子时:
function mytheme_preprocess_node__video(&$variables) {
...
}
Run Code Online (Sandbox Code Playgroud)
这不起作用.我认为我要么不能定义这样的钩子,要么我只是错误地命名它.我找到了一些与此相关的线程,例如这似乎意味着我需要为所有节点定义一个钩子,然后编写一个if语句来分别处理每个类型.所以.......
最后的问题:我可以为整个内容类型定义一个钩子,如果是这样,我做错了什么?
我在(父)段落中有一个实体引用字段,它引用多个子段落。
是否可以访问子级(引用段落)树枝模板中引用段落的字段值?
实际上,我只是想计算引用项目的树枝模板本身之一内的引用项目总数。所以如果你愿意的话,我想计算它的兄弟姐妹+1。
我知道我可以在模块中对此进行预处理,但我想知道这在树枝中是否可行。
我有一个块视图叫做:"MYVIEW"我的模板上有一个叫做"右"的区域.
我应该将模板文件称为什么来编辑它?
以下不起作用.
我正在使用search-theme-form.tpl的自定义版本当我使用搜索框时,我会转移到搜索页面.但搜索实际上并没有发生.搜索结果页面上的搜索框确实有效.这是我的search-them-form.tpl.php文件(演示:
<input type="text" name="search_theme_form_keys" id="edit-search-theme-form-keys" value="Search" title="Enter the terms you wish to search for" class="logininput" height="24px" onblur="restoreSearch(this)" onfocus="clearInput(this)" />
<input type="submit" name="op" id="edit-submit" value="" class="form-submit" style="display: none;" />
<input type="hidden" name="form_token" id="edit-search-theme-form-form-token" value="<?php print drupal_get_token('search_theme_form'); ?>" />
<input type="hidden" name="form_id" id="edit-search-theme-form" value="search_theme_form" />
Run Code Online (Sandbox Code Playgroud)
还有一个javascript文件涉及.我想从代码中可以清楚地看到它的用法:
function trim(str) {
return str.replace(/^\s+|\s+$/g, '');
}
function clearInput(e) {
e.value=""; // clear default text when clicked
e.className="longininput_onfocus"; //change class
}
function restoreSearch(e) {
if (trim(e.value) == '') {
{
e.value="Search"; // reset default …Run Code Online (Sandbox Code Playgroud) drupal-templates ×10
drupal ×5
drupal-7 ×4
drupal-8 ×3
php ×3
drupal-6 ×2
drupal-views ×2
drupal-hooks ×1
hook ×1
javascript ×1
search ×1