Skip to content

Instantly share code, notes, and snippets.

@mortendk
Created September 18, 2013 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortendk/6610523 to your computer and use it in GitHub Desktop.
Save mortendk/6610523 to your computer and use it in GitHub Desktop.
field image twig
{# title wtf is this called label btw #}
{% if not label_hidden %}
<h3 {{ title_attributes }}>{{ label }}:&nbsp;</h3>
{% endif %}
{% for delta, item in items %}
{% if loop.length > 1 %} {# no wrappers if theres only 1 item#}
<section class="images" {{ content_attributes }}> {# wanna do a print all attributes but no class #}
{% endif %}
<figure class="image {{ cycle(["even", "odd"], delta) }}"{{ item_attributes[delta] }}>
{{ item }}
<figcaption>
<pre>{{ dump(item.alt) }}</pre>
</figcaption>
</figure>
{% if loop.length > 1 %}
</section>
{% endif %}
{% endfor %}
@mortendk
Copy link
Author

{{ dump(item) })

array(4) {
["#theme"]=>
string(15) "image_formatter"
["#item"]=>
array(6) {
["target_id"]=>
string(1) "5"
["alt"]=>
string(20) "First EU top meeting"
["title"]=>
string(0) ""
["width"]=>
string(4) "1024"
["height"]=>
string(3) "768"
["entity"]=>
object(Drupal\file\Entity\File)#287 (14) {
["values":protected]=>
array(10) {
["langcode"]=>
array(1) {
["und"]=>
string(3) "und"
}
["fid"]=>
array(1) {
["und"]=>
string(1) "5"
}
["uuid"]=>
array(1) {
["und"]=>
string(36) "a9c150bd-e7f7-4ac9-bc54-84aa2afd25ad"
}
["uid"]=>
array(1) {
["und"]=>
string(1) "1"
}
["filename"]=>
array(1) {
["und"]=>
string(19) "cph2012eudinner.jpg"
}
["uri"]=>
array(1) {
["und"]=>
string(40) "public://field/image/cph2012eudinner.jpg"
}
["filemime"]=>
array(1) {
["und"]=>
string(10) "image/jpeg"
}
["filesize"]=>
array(1) {
["und"]=>
string(6) "532287"
}
["status"]=>
array(1) {
["und"]=>
string(1) "1"
}
["timestamp"]=>
array(1) {
["und"]=>
string(10) "1379515606"
}
}
["bundle":protected]=>
string(4) "file"
["fields":protected]=>
array(2) {
["fid"]=>
array(1) {
["und"]=>
object(Drupal\Core\Entity\Field\Field)#291 (5) {
["list":protected]=>
array(1) {
[0]=>
object(Drupal\Core\Entity\Plugin\DataType\IntegerItem)#292 (5) {
["values":protected]=>
array(1) {
["value"]=>
string(1) "5"
}
["properties":protected]=>
array(0) {
}
["definition":protected]=>
array(5) {
["list"]=>
bool(false)
["label"]=>
string(7) "File ID"
["description"]=>
string(12) "The file ID."
["type"]=>
string(13) "integer_field"
["read-only"]=>
bool(true)
}
["name":protected]=>
int(0)
["parent":protected]=>
RECURSION
}
}
["langcode":protected]=>
string(3) "und"
["definition":protected]=>
array(5) {
["label"]=>
string(7) "File ID"
["description"]=>
string(12) "The file ID."
["type"]=>
string(13) "integer_field"
["read-only"]=>
bool(true)
["list"]=>
bool(true)
}
["name":protected]=>
string(3) "fid"
["parent":protected]=>
RECURSION
}
}
["uri"]=>
array(1) {
["und"]=>
object(Drupal\Core\Entity\Field\Field)#745 (5) {
["list":protected]=>
array(1) {
[0]=>
object(Drupal\Core\Entity\Plugin\DataType\StringItem)#848 (5) {
["values":protected]=>
array(1) {
["value"]=>
string(40) "public://field/image/cph2012eudinner.jpg"
}
["properties":protected]=>
array(0) {
}
["definition":protected]=>
array(4) {
["list"]=>
bool(false)
["label"]=>
string(3) "URI"
["description"]=>
string(52) "The URI to access the file (either local or remote)."
["type"]=>
string(12) "string_field"
}
["name":protected]=>
int(0)
["parent":protected]=>
RECURSION
}
}
["langcode":protected]=>
string(3) "und"
["definition":protected]=>
array(4) {
["label"]=>
string(3) "URI"
["description"]=>
string(52) "The URI to access the file (either local or remote)."
["type"]=>
string(12) "string_field"
["list"]=>
bool(true)
}
["name":protected]=>
string(3) "uri"
["parent":protected]=>
RECURSION
}
}
}
["language":protected]=>
NULL
["languages":protected]=>
array(3) {
["en"]=>
object(Drupal\Core\Language\Language)#121 (7) {
["name"]=>
string(7) "English"
["id"]=>
string(2) "en"
["direction"]=>
int(0)
["weight"]=>
int(0)
["default"]=>
bool(true)
["method_id"]=>
NULL
["locked"]=>
int(0)
}
["und"]=>
object(Drupal\Core\Language\Language)#123 (8) {
["name"]=>
string(13) "Not specified"
["id"]=>
string(3) "und"
["direction"]=>
int(0)
["weight"]=>
int(1)
["default"]=>
bool(false)
["method_id"]=>
NULL
["locked"]=>
bool(true)
["enabled"]=>
bool(true)
}
["zxx"]=>
object(Drupal\Core\Language\Language)#124 (8) {
["name"]=>
string(14) "Not applicable"
["id"]=>
string(3) "zxx"
["direction"]=>
int(0)
["weight"]=>
int(2)
["default"]=>
bool(false)
["method_id"]=>
NULL
["locked"]=>
bool(true)
["enabled"]=>
bool(true)
}
}
["fieldDefinitions":protected]=>
array(10) {
["fid"]=>
array(5) {
["label"]=>
string(7) "File ID"
["description"]=>
string(12) "The file ID."
["type"]=>
string(13) "integer_field"
["read-only"]=>
bool(true)
["list"]=>
bool(true)
}
["uuid"]=>
array(5) {
["label"]=>
string(4) "UUID"
["description"]=>
string(14) "The file UUID."
["type"]=>
string(10) "uuid_field"
["read-only"]=>
bool(true)
["list"]=>
bool(true)
}
["langcode"]=>
array(4) {
["label"]=>
string(13) "Language code"
["description"]=>
string(23) "The file language code."
["type"]=>
string(14) "language_field"
["list"]=>
bool(true)
}
["uid"]=>
array(5) {
["label"]=>
string(7) "User ID"
["description"]=>
string(24) "The user ID of the file."
["type"]=>
string(22) "entity_reference_field"
["settings"]=>
array(1) {
["target_type"]=>
string(4) "user"
}
["list"]=>
bool(true)
}
["filename"]=>
array(4) {
["label"]=>
string(8) "Filename"
["description"]=>
string(41) "Name of the file with no path components."
["type"]=>
string(12) "string_field"
["list"]=>
bool(true)
}
["uri"]=>
array(4) {
["label"]=>
string(3) "URI"
["description"]=>
string(52) "The URI to access the file (either local or remote)."
["type"]=>
string(12) "string_field"
["list"]=>
bool(true)
}
["filemime"]=>
array(4) {
["label"]=>
string(14) "File MIME type"
["description"]=>
string(21) "The file's MIME type."
["type"]=>
string(12) "string_field"
["list"]=>
bool(true)
}
["filesize"]=>
array(4) {
["label"]=>
string(9) "File size"
["description"]=>
string(30) "The size of the file in bytes."
["type"]=>
string(13) "boolean_field"
["list"]=>
bool(true)
}
["status"]=>
array(4) {
["label"]=>
string(6) "Status"
["description"]=>
string(55) "The status of the file, temporary (0) and permanent (1)"
["type"]=>
string(13) "integer_field"
["list"]=>
bool(true)
}
["timestamp"]=>
array(4) {
["label"]=>
string(7) "Created"
["description"]=>
string(35) "The time that the node was created."
["type"]=>
string(13) "integer_field"
["list"]=>
bool(true)
}
}
["uriPlaceholderReplacements":protected]=>
NULL
["activeLangcode":protected]=>
string(3) "und"
["translations":protected]=>
array(1) {
["und"]=>
array(1) {
["status"]=>
int(1)
}
}
["translationInitialize":protected]=>
bool(false)
["entityType":protected]=>
string(4) "file"
["enforceIsNew":protected]=>
NULL
["newRevision":protected]=>
bool(false)
["isDefaultRevision":protected]=>
bool(true)
}
}
["#image_style"]=>
string(5) "large"
["#path"]=>
string(0) ""
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment