我是Drupal主题的新手。我创建了一个名为“mymoduleblock”的块模块,
这是我放在一起的代码的一部分。
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”作为默认模板。我如何使用“specialteme”作为我的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>
答案 0 :(得分:1)
尝试:
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'
)
);
}