Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.42 KB | None | 0 0
  1. {#
  2. /**
  3. * @file
  4. * Theme override for a field.
  5. *
  6. * To override output, copy the "field.html.twig" from the templates directory
  7. * to your theme's directory and customize it, just like customizing other
  8. * Drupal templates such as page.html.twig or node.html.twig.
  9. *
  10. * Instead of overriding the theming for all fields, you can also just override
  11. * theming for a subset of fields using
  12. * @link themeable Theme hook suggestions. @endlink For example,
  13. * here are some theme hook suggestions that can be used for a field_foo field
  14. * on an article node type:
  15. * - field--node--field-foo--article.html.twig
  16. * - field--node--field-foo.html.twig
  17. * - field--node--article.html.twig
  18. * - field--field-foo.html.twig
  19. * - field--text-with-summary.html.twig
  20. * - field.html.twig
  21. *
  22. * Available variables:
  23. * - attributes: HTML attributes for the containing element.
  24. * - label_hidden: Whether to show the field label or not.
  25. * - title_attributes: HTML attributes for the title.
  26. * - label: The label for the field.
  27. * - multiple: TRUE if a field can contain multiple items.
  28. * - items: List of all the field items. Each item contains:
  29. * - attributes: List of HTML attributes for each item.
  30. * - content: The field item's content.
  31. * - entity_type: The entity type to which the field belongs.
  32. * - field_name: The name of the field.
  33. * - field_type: The type of the field.
  34. * - label_display: The display settings for the label.
  35. *
  36. *
  37. * @see template_preprocess_field()
  38. */
  39. #}
  40. {%
  41. set classes = [
  42. 'field',
  43. 'field--name-' ~ field_name|clean_class,
  44. 'field--type-' ~ field_type|clean_class,
  45. 'field--label-' ~ label_display,
  46. ]
  47. %}
  48. {%
  49. set title_classes = [
  50. 'field__label',
  51. label_display == 'visually_hidden' ? 'visually-hidden',
  52. ]
  53. %}
  54. {% if label_hidden %}
  55. <div{{ attributes.addClass(classes) }}>
  56. <div class="field__items">
  57. {% for item in items %}
  58. <div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
  59. {% endfor %}
  60. </div>
  61. </div>
  62. {% else %}
  63. <div{{ attributes.addClass(classes) }}>
  64. <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
  65. <div class="field__items">
  66. {% for item in items %}
  67. <div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
  68. {% endfor %}
  69. </div>
  70. </div>
  71. {% endif %}
  72.  
  73. <!-- THEME DEBUG -->
  74. <!-- THEME HOOK: 'field' -->
  75. <!-- FILE NAME SUGGESTIONS:
  76. x field--default--node--field-category--insight.html.twig
  77. * field--default--node--insight.html.twig
  78. * field--default--node--field-category.html.twig
  79. * field--default--field-category--insight.html.twig
  80. * field--default--insight.html.twig
  81. * field--default--field-category.html.twig
  82. * field--default.html.twig
  83. * field--theme-ds-field-default.html.twig
  84. * field--node--field-category--insight.html.twig
  85. * field--node--field-category.html.twig
  86. * field--node--insight.html.twig
  87. * field--field-category.html.twig
  88. * field--entity-reference.html.twig
  89. * field.html.twig
  90. -->
  91. <!-- BEGIN OUTPUT from 'themes/custom/myproject/myproject_child/templates/field/field--default--node--field-category--insight.html.twig' -->
  92. <div data-quickedit-field-id="node/1/field_category/en/teaser" class="field field--name-field-category field--type-entity-reference field--label-hidden">
  93. <div class="field__items">
  94. <div class="field__item"><a href="/myproject/insights/1" hreflang="en">Legal Services</a></div>
  95. </div>
  96. </div>
  97.  
  98. <!-- END OUTPUT from 'themes/custom/myproject/myproject_child/templates/field/field--default--node--field-category--insight.html.twig' -->
  99.  
  100. <!-- THEME DEBUG -->
  101. <!-- THEME HOOK: 'field' -->
  102. <!-- FILE NAME SUGGESTIONS:
  103. x field--default--node--field-category--insight.html.twig
  104. * field--default--node--insight.html.twig
  105. * field--default--node--field-category.html.twig
  106. * field--default--field-category--insight.html.twig
  107. * field--default--insight.html.twig
  108. * field--default--field-category.html.twig
  109. * field--default.html.twig
  110. * field--theme-ds-field-default.html.twig
  111. * field--node--field-category--insight.html.twig
  112. * field--node--field-category.html.twig
  113. * field--node--insight.html.twig
  114. * field--field-category.html.twig
  115. * field--entity-reference.html.twig
  116. * field.html.twig
  117. -->
  118. <!-- BEGIN OUTPUT from 'themes/custom/myproject/myproject_child/templates/field/field--default--node--field-category--insight.html.twig' -->
  119. <div data-quickedit-field-id="node/1/field_category/en/teaser" class="field field--name-field-category field--type-entity-reference field--label-hidden">
  120. <div class="field__items">
  121. <div class="field__item"><a href="/myproject/insights/2" hreflang="en">Product Liability</a></div>
  122. </div>
  123. </div>
  124.  
  125. <!-- END OUTPUT from 'themes/custom/myproject/myproject_child/templates/field/field--default--node--field-category--insight.html.twig' -->
  126.  
  127. <div class="field__item"><a href="/myproject/insights?tid={{ item.content['#url'].routeParameters.taxonomy_term }}" hreflang="en">Product Liability</a></div>
  128.  
  129. <div{{ attributes.addClass(classes) }}>
  130. <div class="field__items">
  131. {% for item in items %}
  132. {{ kint(item.content) }}
  133. ...
  134. ...
  135.  
  136. {#
  137. /**
  138. * @file
  139. * Theme override for a field.
  140. *
  141. * To override output, copy the "field.html.twig" from the templates directory
  142. * to your theme's directory and customize it, just like customizing other
  143. * Drupal templates such as page.html.twig or node.html.twig.
  144. *
  145. * Instead of overriding the theming for all fields, you can also just override
  146. * theming for a subset of fields using
  147. * @link themeable Theme hook suggestions. @endlink For example,
  148. * here are some theme hook suggestions that can be used for a field_foo field
  149. * on an article node type:
  150. * - field--node--field-foo--article.html.twig
  151. * - field--node--field-foo.html.twig
  152. * - field--node--article.html.twig
  153. * - field--field-foo.html.twig
  154. * - field--text-with-summary.html.twig
  155. * - field.html.twig
  156. *
  157. * Available variables:
  158. * - attributes: HTML attributes for the containing element.
  159. * - label_hidden: Whether to show the field label or not.
  160. * - title_attributes: HTML attributes for the title.
  161. * - label: The label for the field.
  162. * - multiple: TRUE if a field can contain multiple items.
  163. * - items: List of all the field items. Each item contains:
  164. * - attributes: List of HTML attributes for each item.
  165. * - content: The field item's content.
  166. * - entity_type: The entity type to which the field belongs.
  167. * - field_name: The name of the field.
  168. * - field_type: The type of the field.
  169. * - label_display: The display settings for the label.
  170. *
  171. * @see template_preprocess_field()
  172. */
  173. #}
  174. {%
  175. set classes = [
  176. 'field',
  177. 'field--name-' ~ field_name|clean_class,
  178. 'field--type-' ~ field_type|clean_class,
  179. 'field--label-' ~ label_display,
  180. ]
  181. %}
  182. {%
  183. set title_classes = [
  184. 'field__label',
  185. label_display == 'visually_hidden' ? 'visually-hidden',
  186. ]
  187. %}
  188. {% if label_hidden %}
  189. <div{{ attributes.addClass(classes) }}>
  190. <div class="field__items">
  191. {% for item in items %}
  192.  
  193. {% if item.content['#url'].routeParameters['taxonomy_term'] is defined %}
  194.  
  195. <div{{ item.attributes.addClass('field__item') }}><a href="{{ base_path }}insights?tid={{ item.content['#url'].routeParameters['taxonomy_term'] }}">{{ item.content['#title'] }}</a></div>
  196.  
  197. {% else %}
  198.  
  199. <div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
  200.  
  201. {% endif %}
  202.  
  203. {% endfor %}
  204. </div>
  205. </div>
  206. {% else %}
  207. <div{{ attributes.addClass(classes) }}>
  208. <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
  209. <div class="field__items">
  210. {% for item in items %}
  211. <div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
  212. {% endfor %}
  213. </div>
  214. </div>
  215. {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement