Templates Drupal模块块主题
我不熟悉Drupal主题。我创建了一个名为“mymoduleblock”的块模块 这是我编写的代码的一部分Templates Drupal模块块主题,templates,drupal,module,themes,block,Templates,Drupal,Module,Themes,Block,我不熟悉Drupal主题。我创建了一个名为“mymoduleblock”的块模块 这是我编写的代码的一部分 function mymoduleblock_init() { $config = array( 'type' => 'external', 'every_page' => TRUE ); } function mymoduleblock_block_info() { $blocks = array(); $blocks['m
function mymoduleblock_init() {
$config = array(
'type' => 'external',
'every_page' => TRUE
);
}
function mymoduleblock_block_info() {
$blocks = array();
$blocks['mymoduleblock'] = array(
'info' => t('mymoduleblock'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
function mymoduleblock_block_view($delta='') {
switch ($delta) {
case 'mymoduleblock':
$block['subject'] = t("here is title");
$block['content'] = "here is content";
break;
}
return $block;
}
function mymoduleblock_theme() {
return array(
'specialtheme' => array(
'variables' => array('node' => NULL),
'template' => 'specialtheme',
),
);
}
我尝试为我的模板使用不同的名称,因为该模板很可能与其他块共享。但是,它一直给我“block--mymoduleblock.tpl”作为默认模板。如何使用“SpecialTime”作为我的tpl并与其他模块共享
下面是模板的代码
<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?> col-sm-4"<?php print $attributes; ?>>
<div class="content"<?php print $content_attributes; ?>>
<div>
<?php print $content ?>
<br><br>
</div>
</div>
</div>
试试:
实际上,我想把它放在我的主题模板文件夹中,这样我的一些块就可以共享同一个模板。你可以把文件放在你想要的地方。你可以使用drupal_get_path('theme','theme_NAME')。'/templates/'作为路径,当我使用自定义模板时,它会给我未定义的块、html\u块\u id错误。您是否使用了钩子\u块\u信息?因为我没有在这里提到它,但是你必须使用它,我在块模块中有hook\u block\u信息,但是不能将所有变量传递给模板。它一直给我html_block_id未定义的错误。
function mymoduleblock_block_view($delta='') {
switch ($delta) {
case 'mymoduleblock':
$block['subject'] = t("here is title");
$block['content'] = theme('specialtheme', $variables) // array with variables you want to send to your template
break;
}
return $block;
}
function mymoduleblock_theme() {
return array(
'specialtheme' => array(
'file' => 'your_template.tpl.php', // place your file in 'templates' folder of your module folder
'path' => drupal_get_path('module', 'your_module_name') .'/templates'
)
);
}