viewsでインラインスタイル(style="")を除去しないで出力する方法

Events happening in the community are now at Drupal community events on www.drupal.org.
kenppx's picture

いつもお世話になっております。Drupal 7.28 views 7.x-3.8を使用しています。

Viewsのrewrite outputで以下のようにstyle属性を記述すると

<div style="height:; width:;">test</div>

style属性が除去されて以下のように出力されてしまいます。
<div>test</div>

viewsでstyle属性を除去しないで出力する方法がありましたら、教えて頂けないでしょうか?
よろしくお願いします。

Comments

theme_image_styleを使用して解決しました

kenppx's picture

viewsの出力を変えるのではなく、function theme_image_style を利用して特定のイメージスタイルの出力をオーバーライドする事で解決しました。
今回はwall-imagesというイメージスタイルを出力時に以下のようにインラインスタイルを含むdiv要素で囲う事を目的としました。qchan様、ご指導大変ありがとうございました!

<div style="height:  px; width:  px; "><img src="hogehoge" /></div>

以下に私が行った方法です。

①以下のURLにある以下のコードをテーマのtemplate.phpにコピーします。
https://api.drupal.org/api/drupal/modules!image!image.module/function/theme_image_style/7

function theme_image_style($variables) {
  // Determine the dimensions of the styled image.
  $dimensions = array(
    'width' => $variables['width'],
    'height' => $variables['height'],
  );

  image_style_transform_dimensions($variables['style_name'], $dimensions);

  $variables['width'] = $dimensions['width'];
  $variables['height'] = $dimensions['height'];

  // Determine the URL for the styled image.
  $variables['path'] = image_style_url($variables['style_name'], $variables['path']);
  return theme('image', $variables);
}

②コピーしたコードを以下のように変更

function postwalls_image_style($variables) {
  // Determine the dimensions of the styled image.
  $dimensions = array(
    'width' => $variables['width'],
    'height' => $variables['height'],
  );

  image_style_transform_dimensions($variables['style_name'], $dimensions);

  $variables['width'] = $dimensions['width'];
  $variables['height'] = $dimensions['height'];

  // Determine the URL for the styled image.
  $variables['path'] = image_style_url($variables['style_name'], $variables['path']);

if($variables['style_name'] == 'wall-images'){
   return '<div style="height:'.$variables['height'].'px; width:'.$variables['width'].'px;">'.theme('image', $variables).'</div>';
  }else{
   return theme('image', $variables);
}
}

日本 コミュニティ: Drupal Japan User Group

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: