-
-
Notifications
You must be signed in to change notification settings - Fork 157
/
_macro.html.twig
90 lines (74 loc) 路 3.83 KB
/
_macro.html.twig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{# Button Macro with defaults #}
{% macro icon(icon = 'question-circle') %}{% apply spaceless %}
{% set icon = icon|replace({'fa-': ''}) %}
<i class="fas fa-fw fa-{{ icon }}"></i>
{% endapply %}{% endmacro %}
{% macro button(label = 'Button', icon = 'question-circle', class = 'tertiary', attr = []) %}{% apply spaceless %}
{% set label = label|trans %}
{% set icon = icon|replace({'fa-': ''}) %}
{% set class = class|replace({'btn-': ''}) %}
{% set mb = 'mb-' in class ? '' : 'mb-3' %}
{% set attr = attr %}
<button class="btn btn-{{ class }} {{ mb }}"
{% for key,value in attr %} {{ key }}="{{value}}"{% endfor %}>
<i class="fas fa-fw fa-{{ icon }} mr-2"></i>
{{- label -}}
</button>
{% endapply %}{% endmacro %}
{% macro buttonlink(label = 'Button', link = '', icon = 'question-circle', class = 'tertiary', attr = [], translate = true) %}{% apply spaceless %}
{% if translate %}
{% set label = label|trans %}
{% endif %}
{% set icon = icon|replace({'fa-': ''}) %}
{% set class = class|replace({'btn-': ''}) %}
{% set mb = 'mb-' in class ? '' : 'mb-3' %}
{% set attr = attr %}
<a href="{{ link }}" class="btn btn-{{ class|split(' ')|join(' btn-') }} text-nowrap {{ mb }}"
{% for key,value in attr %} {{ key }}="{{value}}"{% endfor %}>
<i class="fas fa-fw fa-{{ icon }} mr-1"></i>
{{- label -}}
</a>
{% endapply %}{% endmacro %}
{% macro generate_collection_fields(collectionField, fields, record, compileTemplates) %}{% apply spaceless %}
{% set fieldsHtml = [] %}
{% for item_field in fields %}
{% set collectionItemName = 'collections[' ~ collectionField.name ~ '][' ~ item_field.definition.name ~ ']' %}
{# we create a 'dummy' hash from the current loop index, which is used to instantiate copies of collection item templates. #}
{# The order is also submitted in an order field, so that collection items may be stored in the given order in the database. #}
{% set hash = compileTemplates == true ? "{{ hash }}" : loop.index %}
{% set collectionItemName = collectionItemName ~ '[' ~ hash ~ ']' %}
{% set id = 'field-' ~ collectionField.name|default('unnamed') ~ '-' ~ item_field.name|default('unnamed') ~ '-' ~ hash %}
{% set new_field %}
{% set context = {
'field': item_field,
'id': id,
'in_collection': true,
'is_first': loop.index0 == 0,
'is_last': loop.index == fields|length,
'name': collectionItemName,
'collection_name': collectionField.name,
'collection_label': collectionField.definition.label,
'hash': hash,
'record': record
} %}
{% if item_field.type != 'set' %}
{% set context = context|merge({'include_id': true}) %}
{% endif %}
{% set includeLookup = [
'@bolt/_partials/fields/' ~ item_field.type ~ '.html.twig',
'@' ~ item_field.type ~ '/' ~ item_field.type ~ '.html.twig',
'@bolt/_partials/fields/generic.html.twig'
] %}
{% include includeLookup with context only %}
{% endset %}
{# set the label manually as set in _base.html.twig, to pass to Collection.vue for templates #}
{% set label = item_field.definition.label|default(item_field.name|default('unnamed')|ucwords) %}
{% set fieldsHtml = fieldsHtml|merge([{'html': new_field, 'hash': hash, 'label': label}]) %}
{% endfor %}
{{ fieldsHtml|json_encode }}
{% endapply %}{% endmacro %}
{% macro relative_datetime(datetime) %}{% apply spaceless %}
<abbr class="datetime-relative" title="{{ datetime|localdate }}">
{{- datetime|date('c') -}}
</abbr>
{% endapply %}{% endmacro %}