我真的不知道还有什么可以尝试。
我创建了一种内容类型"优惠"在Drupal 8中有一些字段,标题,正文和图像。通过使用实体浏览器上载或选择图像字段来填充图像字段。 (使用核心中的媒体模块,使用图像媒体包等。)
我还使用段落模块创建了一个段落类型,该段落模块包含内容类型商品的实体引用字段。
为了对段落进行主题化,我创建了一个段落 - offer.htm.twig文件,我只需使用{{content}}即可查看商品中的所有内容。现在,我想单独显示每个字段,因为我想添加自己的html包装器和CSS样式。
我在单独获取标题和正文字段方面没有任何问题:
{{content.field_offer_id [0] [' #stode']。label | striptags}}
{{content.field_offer_id [0] ['#node']。field_body.value | striptags}}
其中field_offer_id是包含商品的段落字段的机器名称
但是获得图像uri,只是没有工作,我想我尝试了一切,但似乎没有任何工作。这是我尝试过的,是的,其中一些可能没有意义,但我只是出于绝望而尝试一切:
这正确地为我提供了ID,因此我知道图像在那里:
{{content.field_offer_id [0] [' #stode'] .field_offer_image.target_id}}
所有这些都不会返回值
{{file_url(content.field_offer_id [0] [' #stode'] .field_offer_image.entity.value)}}
{{file_url(content.field_offer_id [0] ['#node']。field_offer_image.entity.fileuri)}}
{{file_url(content.field_offer_id [0] ['#node']。field_offer_image.entity.uri.value)}}
{{content.field_offer_id [0] [' #stode']。get_fields(' field_offer_image')。entity.url()}}
{{content.field_offer_id [0] ['#node']。get_fields(' field_offer_image')。entity.uri}}
{{content.field_offer_id [0] ['#node']。field_offer_image.entity.fileuri.value}}
{{content.field_offer_id [0] ['#node']。field_offer_image.entity.uri.value | image_style(' offer')}}
{{content.field_offer_id [0] ['#node']。field_offer_image.entity.fileuri | image_style(' offer')}}
这是kpr转储 {{kpr(content.field_offer_id [0] [' #stode']。field_offer_image.0.entity)}}
stdClass Object
( [ CLASS ] => Drupal的\媒体\实体\媒体 [values:protected] =>排列 ( [vid] =>排列 ( [x-default] => 7 )
[langcode] => Array
(
[x-default] => en
)
[revision_user] => Array
(
[x-default] =>
)
[revision_created] => Array
(
[x-default] => 1524854915
)
[revision_log_message] => Array
(
[x-default] =>
)
[revision_default] => Array
(
[x-default] => 1
)
[mid] => Array
(
[x-default] => 7
)
[bundle] => Array
(
[x-default] => image
)
[uuid] => Array
(
[x-default] => eb9bb08d-37fa-4900-af14-aa5527f378e4
)
[isDefaultRevision] => Array
(
[x-default] => 1
)
[status] => Array
(
[x-default] => 1
)
[name] => Array
(
[x-default] => Seaworld offer
)
[thumbnail] => Array
(
[x-default] => Array
(
[target_id] => 7
[alt] => Thumbnail
[title] => Seaworld offer
[width] => 567
[height] => 373
)
)
[uid] => Array
(
[x-default] => 1
)
[created] => Array
(
[x-default] => 1524854890
)
[changed] => Array
(
[x-default] => 1524854915
)
[default_langcode] => Array
(
[x-default] => 1
)
[revision_translation_affected] => Array
(
[x-default] => 1
)
[field_image_type] => Array
(
[x-default] => Array
(
[0] => Array
(
[target_id] => 1
)
)
)
[field_media_image] => Array
(
[x-default] => Array
(
[0] => Array
(
[target_id] => 7
[alt] => Seaworld offer
[title] =>
[width] => 567
[height] => 373
)
)
)
)
[fields:protected] => Array
(
)
[fieldDefinitions:protected] =>
[languages:protected] =>
[langcodeKey:protected] => langcode
[defaultLangcodeKey:protected] => default_langcode
[activeLangcode:protected] => x-default
[defaultLangcode:protected] => en
[translations:protected] => Array
(
[x-default] => Array
(
[status] => 1
)
)
[translationInitialize:protected] =>
[newRevision:protected] =>
[isDefaultRevision:protected] => 1
[entityKeys:protected] => Array
(
[bundle] => image
[id] => 7
[revision] => 7
[uuid] => eb9bb08d-37fa-4900-af14-aa5527f378e4
)
[translatableEntityKeys:protected] => Array
(
[label] => Array
(
[x-default] => Seaworld offer
)
[langcode] => Array
(
[x-default] => en
)
[published] => Array
(
[x-default] => 1
)
[default_langcode] => Array
(
[x-default] => 1
)
[revision_translation_affected] => Array
(
[x-default] => 1
)
)
[validated:protected] =>
[validationRequired:protected] =>
[loadedRevisionId:protected] => 7
[revisionTranslationAffectedKey:protected] => revision_translation_affected
[enforceRevisionTranslationAffected:protected] => Array
(
)
[entityTypeId:protected] => media
[enforceIsNew:protected] =>
[typedData:protected] => stdClass Object
(
[__CLASS__] => Drupal\Core\Entity\Plugin\DataType\EntityAdapter
[entity:protected] => stdClass Object
(
[__CLASS__] => Drupal\media\Entity\Media
[values:protected] => Array
(
[vid] => Array
(
[x-default] => 7
)
[langcode] => Array
(
[x-default] => en
)
[revision_user] => Array
(
[x-default] =>
)
[revision_created] => Array
(
[x-default] => 1524854915
)
[revision_log_message] => Array
(
[x-default] =>
)
[revision_default] => Array
(
[x-default] => 1
)
[mid] => Array
(
[x-default] => 7
)
[bundle] => Array
(
[x-default] => image
)
[uuid] => Array
(
[x-default] => eb9bb08d-37fa-4900-af14-aa5527f378e4
)
[isDefaultRevision] => Array
(
[x-default] => 1
)
[status] => Array
(
[x-default] => 1
)
[name] => Array
(
[x-default] => Seaworld offer
)
[thumbnail] => Array
(
[x-default] => Array
(
[target_id] => 7
[alt] => Thumbnail
[title] => Seaworld offer
[width] => 567
[height] => 373
)
)
[uid] => Array
(
[x-default] => 1
)
[created] => Array
(
[x-default] => 1524854890
)
[changed] => Array
(
[x-default] => 1524854915
)
[default_langcode] => Array
(
[x-default] => 1
)
[revision_translation_affected] => Array
(
[x-default] => 1
)
[field_image_type] => Array
(
[x-default] => Array
(
[0] => Array(1)
)
)
[field_media_image] => Array
(
[x-default] => Array
(
[0] => Array(5)
)
)
)
[fields:protected] => Array
(
)
[fieldDefinitions:protected] =>
[languages:protected] =>
[langcodeKey:protected] => langcode
[defaultLangcodeKey:protected] => default_langcode
[activeLangcode:protected] => x-default
[defaultLangcode:protected] => en
[translations:protected] => Array
(
[x-default] => Array
(
[status] => 1
)
)
[translationInitialize:protected] =>
[newRevision:protected] =>
[isDefaultRevision:protected] => 1
[entityKeys:protected] => Array
(
[bundle] => image
[id] => 7
[revision] => 7
[uuid] => eb9bb08d-37fa-4900-af14-aa5527f378e4
)
[translatableEntityKeys:protected] => Array
(
[label] => Array
(
[x-default] => Seaworld offer
)
[langcode] => Array
(
[x-default] => en
)
[published] => Array
(
[x-default] => 1
)
[default_langcode] => Array
(
[x-default] => 1
)
[revision_translation_affected] => Array
(
[x-default] => 1
)
)
[validated:protected] =>
[validationRequired:protected] =>
[loadedRevisionId:protected] => 7
[revisionTranslationAffectedKey:protected] => revision_translation_affected
[enforceRevisionTranslationAffected:protected] => Array
(
)
[entityTypeId:protected] => media
[enforceIsNew:protected] =>
[typedData:protected] => stdClass Object
(
[__CLASS__] => Drupal\Core\Entity\Plugin\DataType\EntityAdapter
[entity:protected] => stdClass Object
(
[__CLASS__] => Drupal\media\Entity\Media
[values:protected] => Array
(
[vid] => Array(1)
[langcode] => Array(1)
[revision_user] => Array(1)
[revision_created] => Array(1)
[revision_log_message] => Array(1)
[revision_default] => Array(1)
[mid] => Array(1)
[bundle] => Array(1)
[uuid] => Array(1)
[isDefaultRevision] => Array(1)
[status] => Array(1)
[name] => Array(1)
[thumbnail] => Array(1)
[uid] => Array(1)
[created] => Array(1)
[changed] => Array(1)
[default_langcode] => Array(1)
[revision_translation_affected] => Array(1)
[field_image_type] => Array(1)
[field_media_image] => Array(1)
)
[fields:protected] => Array
(
)
[fieldDefinitions:protected] =>
[languages:protected] =>
[langcodeKey:protected] => langcode
[defaultLangcodeKey:protected] => default_langcode
[activeLangcode:protected] => x-default
[defaultLangcode:protected] => en
[translations:protected] => Array
(
[x-default] => Array(1)
)
[translationInitialize:protected] =>
[newRevision:protected] =>
[isDefaultRevision:protected] => 1
[entityKeys:protected] => Array
(
[bundle] => image
[id] => 7
[revision] => 7
[uuid] => eb9bb08d-37fa-4900-af14-aa5527f378e4
)
[translatableEntityKeys:protected] => Array
(
[label] => Array(1)
[langcode] => Array(1)
[published] => Array(1)
[default_langcode] => Array(1)
[revision_translation_affected] => Array(1)
)
[validated:protected] =>
[validationRequired:protected] =>
[loadedRevisionId:protected] => 7
[revisionTranslationAffectedKey:protected] => revision_translation_affected
[enforceRevisionTranslationAffected:protected] => Array
(
)
[entityTypeId:protected] => media
[enforceIsNew:protected] =>
[typedData:protected] => stdClass Object
(
[__CLASS__] => Drupal\Core\Entity\Plugin\DataType\EntityAdapter
[entity:protected] => Drupal\media\Entity\Media
[definition:protected] => Drupal\Core\Entity\TypedData\EntityDataDefinition
[name:protected] =>
[parent:protected] =>
[stringTranslation:protected] =>
[typedDataManager:protected] =>
)
[cacheContexts:protected] => Array
(
)
[cacheTags:protected] => Array
(
)
[cacheMaxAge:protected] => -1
[_serviceIds:protected] => Array
(
)
[stringTranslation:protected] =>
)
[definition:protected] => stdClass Object
(
[__CLASS__] => Drupal\Core\Entity\TypedData\EntityDataDefinition
[propertyDefinitions:protected] =>
[definition:protected] => Array
(
[constraints] => Array(2)
)
[typedDataManager:protected] =>
)
[name:protected] =>
[parent:protected] =>
[stringTranslation:protected] =>
[typedDataManager:protected] =>
)
[cacheContexts:protected] => Array
(
)
[cacheTags:protected] => Array
(
)
[cacheMaxAge:protected] => -1
[_serviceIds:protected] => Array
(
)
[stringTranslation:protected] =>
)
[definition:protected] => stdClass Object
(
[__CLASS__] => Drupal\Core\Entity\TypedData\EntityDataDefinition
[propertyDefinitions:protected] =>
[definition:protected] => Array
(
[constraints] => Array
(
[EntityType] => media
[Bundle] => Array
(
[0] => image
)
)
)
[typedDataManager:protected] =>
)
[name:protected] =>
[parent:protected] =>
[stringTranslation:protected] =>
[typedDataManager:protected] =>
)
[cacheContexts:protected] => Array
(
)
[cacheTags:protected] => Array
(
)
[cacheMaxAge:protected] => -1
[_serviceIds:protected] => Array
(
)
[stringTranslation:protected] =>
)