Это код файла vegas.module. он используется для загрузки изображений из определенной папки.
function vegas_init() {
// Load all the images to be added to Vegas.
$backgrounds = array();
$fade = variable_get('vegas_fade', 0);
for ($i = 0; $i < 10; $i++) {
$fid = variable_get('vegas_images_' . $i, '');
if (!empty($fid)) {
$image = file_load($fid);
if ($image) {
$background = array(
'src' => file_create_url($image->uri),
);
if (!empty($fade)) {
$background['fade'] = intval($fade);
}
$backgrounds[] = $background;
}
}
}
Я печатаю его в файле.module. Это дает ожидаемый результат.
print_r($backgrounds);
Если я напечатаю его в моей теме page.tpl.php, он не вернет никаких значений. Есть ли способ загрузить переменную модуля
Если вы хотите напечатать эту переменную в файле page.tpl.php - используйте страницу hook_preprocess_page
function custom_preprocess_page (& $ variables), а не узел.
Название моей темы - обычай. Вот что я вложил в файл template.php
function custom_preprocess_node(&$variables) { //can be MYTHEME_preprocess_node and locate in template.php
// Load all the images to be added to Vegas.
$backgrounds = array();
$fade = variable_get('vegas_fade', 0);
for ($i = 0; $i < 10; $i++) {
$fid = variable_get('vegas_images_' . $i, '');
if (!empty($fid)) {
$image = file_load($fid);
if ($image) {
$background = array(
'src' => file_create_url($image->uri),
);
if (!empty($fade)) {
$background['fade'] = intval($fade);
}
$variables['backgrounds'][] = $background;
}
}
}
}
и распечатайте файл page.tpl.php
print_r($backgrounds);
Вам нужно использовать страницу hook_preprocess_page для добавления переменных в шаблон страницы или hook_preprocess_node для добавления шаблона переменной в узел.
https://api.drupal.org/api/drupal/modules!node!node.module/function/template_preprocess_node/7
function MYMODULE_preprocess_node(&$variables) { //can be MYTHEME_preprocess_node and locate in template.php
// Load all the images to be added to Vegas.
$backgrounds = array();
$fade = variable_get('vegas_fade', 0);
for ($i = 0; $i < 10; $i++) {
$fid = variable_get('vegas_images_' . $i, '');
if (!empty($fid)) {
$image = file_load($fid);
if ($image) {
$background = array(
'src' => file_create_url($image->uri),
);
if (!empty($fade)) {
$background['fade'] = intval($fade);
}
$variables['backgrounds'][] = $background;
}
}
}
Попробуйте этот код, и в yoot node.tpl.php будет доступен массив $ backgrounds.
Я думаю, правильнее поместить этот код в template.php в вашу тему. Проще всего будет видеть, как измененные переменные узла