Добрый день! Задача такая:
Есть тип материала с полем 'fiel_img'. Вопрос такой:
Как обернуть весь материал ноды в блок и задать ему фоном эту картинку, а само поле 'field_img', соответственно убрать со страницы?
Пользуюсь модулем Display Suite, моего ума пока хватило только на это:
<?php
/**
* file
* Display Suite 1 column template.
*/
?>
<<?php
print $ds_content_wrapper;
print $layout_attributes;
?> class="ds-1col <?php print $classes; ?> clearfix">
<?php if (isset($title_suffix['contextual_links'])): ?>
<?php print render($title_suffix['contextual_links']); ?>
<?php endif; ?>
<div class="block" style="background: url('<?php print file_create_url($content['field_img']['#items'][0]['uri']); ?>') no-repeat;">
<?php print $ds_content; ?>
</div>
</<?php print $ds_content_wrapper ?>>
<?php if (!empty($drupal_render_children)): ?>
<?php print $drupal_render_children ?>
<?php endif; ?>
Вроде бы то что надо, но как теперь убрать поле 'field_img'? Просто скрыть стилями не пойдет.
Комментарии
ЕМНИП, display suite поддерживает токены в аттрибутах в Expert Mode. Поэтому, как я полагаю, вполне достаточно модуля image_url_formatter и токена типа [node:field-image]
Ну и вариант №2 - забить на Display Suite для данной ноды и вьюмода, и тупо заюзать классические шаблоны + preprocess
Знать бы как их заюзать)
В template.php:
<?php
function YOURTHEME_preprocess_node(&$variables, $hook) {
if (isset($variables['view_mode'])) {
$variables['theme_hook_suggestions'][] = 'node__' . $variables['node']->type . '__' . $variables['view_mode'];
}
if (
$variables['node']->type === 'slide') {$variables['slide_url'] = image_style_url('slide_1920x620', $variables['field_slide_image'][0]['uri']);
}
}
?>
Теперь можно переопределять шаблон ноды для конкретного вьюмода
Файл node--slide--teaser.tpl.php
<?php
<div class="slide" style="background-image: url('<?php print $slide_url; ?>')">
<div class="row">
<div class="slide-title"><?php print $title; ?></div>
<div class="slide-caption"><?php print render($content['field_summary']); ?></div>
<div class="slide-link"><?php print render($content['field_slide_link']); ?></div>
</div>
</div>
?>
Ну и отключить использование Display Suite у того вьюмода.
Рецепт, естественно приблизительный, может и с Display Suite взлетит. Но это не точно.
Благодарю, буду пробовать