English 中文(简体)
将数据属性添加到 Drupal 视图图像
原标题:Add data attribute to Drupal Views image

我可以看到打印标题、 正文和图像字段。 现在我要打印一个显示图像标记的数据属性。 当它产生以下 HTML 时 :

<img width="578" height="472" src="http://mydomain.com/sites/mydomain.com/files/image-small.jpg" typeof="foaf:Image">

但我要提供一个更大的图像的 URL 作为数据属性 。 例如 :

<img width="578" height="472" src="http://mydomain.com/sites/mydomain.com/files/image-small.jpg" typeof="foaf:Image" data-big-image="http://mydomain.com/sites/mydomain.com/files/image-big.jpg" />

怎样才能做到这一点? 我能在视图中做吗? 或者我需要修改模板来查看模板吗?

问题回答

访问全部数据的任何简单方式就是在视图 ui 中添加一个节点 id 字段,然后在模板文件中添加一个节点 id 字段,然后在循环输入以下内容:

  $nid = strip_tags($fields[ nid ]->content);
  $node = node_load($nid);

请用 $node 的 var_ dump () 来查看您可以玩用的数据 。

例如,获取您的图像路径将类似于以下内容:

$node->field_cl_image[ und ][0][ uri ]

您可以使用 < a href=" http://drupal.org/project/views_php" rel = "nofollow" > OptionPHP 字段在视图界面中完全完成。

您会想要先添加大小图像字段, 然后将其从显示中排除, 这样您就可以在稍后使用 $Data 对象时轻松引用它们 。

添加 PHP 字段,留空值代码。在输出代码中,只需构建您想要的 HTML :

<?php
print  <img src="  . $data->field_your_small_image_field[ some ][ array ] .
  " data-big-image="  . $data->field_your_big_image_field[ some ][ array ] .  " /> ;
?>`

在输出代码区域中做 dsm($data); (加上Devel 启用) 以查找 URL 的确切数组密钥 。





相关问题
Using QCView and iSight to capture image

I have a QCView that loads a Quartz file which gives you iSights feedback (basically like a QTCaptureView) Everything displays fine The button simply takes a snapshot using the following simple ...

Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple s built-in iSight? I ve seen lots of tutorials on recording video but none on simply taking a picture. Any ...

Transform rectangular image into trapezoid

In .NET how can I transform an image into a trapezoid. The Matrix class supports rotation, shear, etc, but I can t see a trapezoidal transformation. I m using the usual System.Drawing.* API, but I m ...

Rotate image through Y-axis on web page

What are my options for rotating an image on a web page through the Y-axis? I m not sure if I even have the terminology right. Is this called a rotate or a transform. Most of the searches that I ve ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

Convert from 32-BPP to 8-BPP Indexed (C#)

I need to take a full color JPG Image and remap it s colors to a Indexed palette. The palette will consist of specific colors populated from a database. I need to map each color of the image to it s "...

热门标签