我创建了一种称为策略的内容类型,希望将其显示为视图。我为此内容类型创建了字段,例如标题,正文,图像,文件。我需要显示缩略图图像的图像字段,该政策的文件将是pdf上传。我使用以下参数创建了一个视图:
views/views-view--mytheme--page-3.html.twig
<section id="services" class="sub services-bg wow fadeInUp">
<div class="container">
<h2>What We <span>Do</span> </h2>
<div class="row">
{% for result in view.result %}
{% if loop.index == 2 %}
{% endif %}
<div class="col-md-4 col-sm-4 col-xs-12 services-page wow fadeInUp">
<div class="services-item">
<a href="{{ basepath }}/node/{{ view.field.nid.value(view.result[loop.index-1]) }}">
<img src="{{ file_url(view.field.uri.value(view.result[loop.index-1])) }}"
alt="{{ view.field.title.value(view.result[loop.index-1]) }}">
<div class="services-caption text-center">
<h5>{{ view.field.title.value(view.result[loop.index-1]) }}</h5>
<p>{{ view.field.field.file.value(view.result[loop.index-1]) }}</p>
</div></a>
</div>
</div>
{% endfor %}
</div>
</div>
</section>
我想在
标签中显示我的文件uri。目前使用view.field.uri.value
,我只获得图像uri。在dump(result)
上,我得到以下字段:
["field_images_target_id"] => object(Drupal\ file\ Entity\ File) #1520 (27) { ["values":protected]= > array(11) {
["fid"] => array(1) {
["x-default"] => string(2)
"79"
} ["uuid"] => array(1) {
["x-default"] => string(36)
"4a1419f4-75cb-44e1-a305-b571eee75874"
} ["langcode"] => array(1) {
["x-default"] => array(1) {
[0] => array(1) {
["value"] => string(2)
"en"
}
}
} ["uid"] => array(1) {
["x-default"] => string(1)
"1"
} ["filename"] => array(1) {
["x-default"] => string(16)
"gen5EC8.tmp.jpeg"
} ["uri"] => array(1) {
["x-default"] => string(33)
"public://2019-01/gen5EC8.tmp.jpeg"
} ["filemime"] => array(1) {
["x-default"] => string(10)
"image/jpeg"
} ["filesize"] => array(1) {
["x-default"] => string(4)
"4596"
} ["status"] => array(1) {
["x-default"] => string(1)
"1"
} ["created"] => array(1) {
["x-default"] => string(10)
"1546704262"
} ["changed"] => array(1) {
["x-default"] => string(10)
"1546704262"
}
}
["field_file_target_id"] => object(Drupal\ file\ Entity\ File) #1518 (27) { ["values":protected]= > array(11) {
["fid"] => array(1) {
["x-default"] => string(2)
"78"
} ["uuid"] => array(1) {
["x-default"] => string(36)
"87ad74bf-8fd8-4b7a-b90b-406df6bf5926"
} ["langcode"] => array(1) {
["x-default"] => array(1) {
[0] => array(1) {
["value"] => string(2)
"en"
}
}
} ["uid"] => array(1) {
["x-default"] => string(1)
"1"
} ["filename"] => array(1) {
["x-default"] => string(14)
"jK6hSisN7m.txt"
} ["uri"] => array(1) {
["x-default"] => string(31)
"public://2019-01/jK6hSisN7m.txt"
} ["filemime"] => array(1) {
["x-default"] => string(10)
"text/plain"
} ["filesize"] => array(1) {
["x-default"] => string(3)
"796"
} ["status"] => array(1) {
["x-default"] => string(1)
"1"
} ["created"] => array(1) {
["x-default"] => string(10)
"1546704262"
} ["changed"] => array(1) {
["x-default"] => string(10)
"1546704262"
}
}
如何同时使用该字段的uri?我尝试了view.field_images_target_id.uri.value
和view.field_file_target_id.uri.value
,但是它们不起作用。