Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
525 lines (478 sloc) 19.9 KB
{# Template blocks to be used by content fields #}
{# Block naming convention is <fieldDefinitionIdentifier>_field #}
{# Following variables are passed:
# - \eZ\Publish\API\Repository\Values\Content\Field field the field to display
# - \eZ\Publish\API\Repository\Values\Content\ContentInfo contentInfo the contentInfo to which the field belongs to
# - \eZ\Publish\API\Repository\Values\Content\VersionInfo versionInfo the versionInfo to which the field belongs to
# - mixed fieldSettings settings of the field (depends on the fieldtype)
# - array parameters options passed to ez_render_field under the parameters key
# - array attr the attributes to add the generate HTML, contains at least a "class" entry
# containing <fieldtypeidentifier>-field
#}
{% trans_default_domain "content_fields" %}
{% block ezstring_field %}
{% spaceless %}
{% set field_value = field.value.text %}
{{ block( 'simple_inline_field' ) }}
{% endspaceless %}
{% endblock %}
{% block eztext_field %}
{% spaceless %}
{% set field_value = field.value|nl2br %}
{{ block( 'simple_block_field' ) }}
{% endspaceless %}
{% endblock %}
{% block ezrichtext_field %}
{%- set field_value = field.value.xml|richtext_to_html5 -%}
{{ block( 'simple_block_field' ) }}
{% endblock %}
{% block ezauthor_field %}
{% spaceless %}
{% if field.value.authors|length() > 0 %}
<ul {{ block( 'field_attributes' ) }}>
{% for author in field.value.authors %}
<li><a href="mailto:{{ author.email|escape( 'url' ) }}">{{ author.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezcountry_field %}
{% spaceless %}
{% if fieldSettings.isMultiple and field.value.countries|length > 0 %}
<ul {{ block( 'field_attributes' ) }}>
{% for country in field.value.countries %}
<li>{{ country['Name'] }}</li>
{% endfor %}
</ul>
{% elseif field.value.countries|length() == 1 %}
<p {{ block( 'field_attributes' ) }}>
{% for country in field.value.countries %}
{{ country['Name'] }}
{% endfor %}
</p>
{% endif %}
{% endspaceless %}
{% endblock %}
{# @todo: add translate filter #}
{% block ezboolean_field %}
{% spaceless %}
{% set field_value = field.value.bool ? 'Yes' : 'No' %}
{{ block( 'simple_inline_field' ) }}
{% endspaceless %}
{% endblock %}
{% block ezdatetime_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
{% if fieldSettings.useSeconds %}
{% set field_value = field.value.value|localizeddate( 'short', 'medium', parameters.locale ) %}
{% else %}
{% set field_value = field.value.value|localizeddate( 'short', 'short', parameters.locale ) %}
{% endif %}
{{ block( 'simple_block_field' ) }}
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezdate_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
{% set field_value = field.value.date|localizeddate( 'short', 'none', parameters.locale, false ) %}
{{ block( 'simple_block_field' ) }}
{% endif %}
{% endspaceless %}
{% endblock %}
{% block eztime_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
{% if fieldSettings.useSeconds %}
{% set field_value = field.value.time|localizeddate( 'none', 'medium', parameters.locale, 'UTC' ) %}
{% else %}
{% set field_value = field.value.time|localizeddate( 'none', 'short', parameters.locale, 'UTC' ) %}
{% endif %}
{{ block( 'simple_block_field' ) }}
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezemail_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
{% set field_value = field.value.email %}
<a href="mailto:{{ field.value.email|escape( 'url' ) }}" {{ block( 'field_attributes' ) }}>{{ field.value.email }}</a>
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezinteger_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
{% set field_value = field.value.value %}
{{ block( 'simple_inline_field' ) }}
{% endif %}
{% endspaceless %}
{% endblock %}
{# @todo: handle localization #}
{% block ezfloat_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
{% set field_value = field.value.value %}
{{ block( 'simple_inline_field' ) }}
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezurl_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
<a href="{{ field.value.link }}"
{{ block( 'field_attributes' ) }}>{{ field.value.text ? field.value.text : field.value.link }}</a>
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezisbn_field %}
{% spaceless %}
{% set field_value = field.value.isbn %}
{{ block( 'simple_inline_field' ) }}
{% endspaceless %}
{% endblock %}
{% block ezkeyword_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
<ul {{ block( 'field_attributes' ) }}>
{% for keyword in field.value.values %}
<li>{{ keyword }}</li>
{% endfor %}
</ul>
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezselection_field %}
{% spaceless %}
{% set options = fieldSettings.options %}
{% if fieldSettings.multilingualOptions[field.languageCode] is defined %}
{% set options = fieldSettings.multilingualOptions[field.languageCode] %}
{% elseif fieldSettings.multilingualOptions[contentInfo.mainLanguageCode] is defined %}
{% set options = fieldSettings.multilingualOptions[contentInfo.mainLanguageCode] %}
{% endif %}
{% if field.value.selection|length() <= 0 %}
{% elseif fieldSettings.isMultiple %}
<ul {{ block( 'field_attributes' ) }}>
{% for selectedIndex in field.value.selection %}
<li>{{ options[selectedIndex] }}</li>
{% endfor %}
</ul>
{% else %}
{% set field_value = options[field.value.selection.0] %}
{{ block( 'simple_block_field' ) }}
{% endif %}
{% endspaceless %}
{% endblock %}
{# @todo:
# - add translate filter
# - legacy used to dump is_locked attribute
#}
{% block ezuser_field %}
{% spaceless %}
<dl {{ block( 'field_attributes' ) }}>
<dt>User ID</dt>
<dd>{{ field.value.contentId }}</dd>
<dt>Username</dt>
<dd>{{ field.value.login }}</dd>
<dt>Email</dt>
<dd><a href="mailto:{{ field.value.email|escape( 'url' ) }}">{{ field.value.email }}</a></dd>
<dt>Account status</dt>
<dd>{{ field.value.enabled ? 'enabled' : 'disabled' }}</dd>
</dl>
{% endspaceless %}
{% endblock %}
{% block ezbinaryfile_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
{% set route_reference = ez_route( 'ez_content_download', { 'content': content, 'fieldIdentifier': field.fieldDefIdentifier } ) %}
<a href="{{ path( route_reference ) }}"
{{ block( 'field_attributes' ) }}>{{ field.value.fileName }}</a>&nbsp;({{ field.value.fileSize|ez_file_size( 1 ) }})
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezmedia_field %}
{% if not ez_is_field_empty( content, field ) %}
{% spaceless %}
{% set type = fieldSettings.mediaType %}
{% set value = field.value %}
{% set route_reference = ez_route( 'ez_content_download', {'content': content, 'fieldIdentifier': field.fieldDefIdentifier} ) %}
{% set download = path( route_reference ) %}
{% set width = value.width > 0 ? 'width="' ~ value.width ~ '"' : "" %}
{% set height = value.height > 0 ? 'height="' ~ value.height ~ '"' : "" %}
<div {{ block( 'field_attributes' ) }}>
{% autoescape false %}
{% if type == "html5_video"
or type == "quick_time"
or type == "windows_media_player"
or type == "real_player" %}
<video src="{{ download }}" {{ width }} {{ height }}
{{ value.autoplay ? 'autoplay="autoplay"' : "" }}
{{ value.hasController ? 'controls="controls"' : "" }}
{{ value.loop ? 'loop="loop"' : "" }}>
Your browser does not support html5 video.
</video>
{% elseif type == "html5_audio" %}
<audio src="{{ download }}"
{{ value.autoplay ? 'autoplay="autoplay"' : "" }}
{{ value.hasController ? 'controls="controls"' : "" }}
{{ value.loop ? 'loop="loop"' : "" }}
preload="none">
Your browser does not support html5 audio.
</audio>
{% elseif type == 'flash' %}
<object type="application/x-shockwave-flash" {{ width }} {{ height }} data="{{ download }}">
<param name="movie" value="{{ download }}" />
<param name="play" value="{{ value.autoplay ? 'true' : 'false' }}" />
<param name="loop" value="{{ value.loop ? 'true' : 'false' }}" />
<param name="quality" value="{{ value.quality }}" />
</object>
{% elseif type == 'silverlight' %}
<script type="text/javascript">
function onErrorHandler(sender, args) { }
function onResizeHandler(sender, args) { }
</script>
<object data="data:application/x-silverlight," type="application/x-silverlight-2" {{ width }} {{ height }}>
<param name="source" value="{{ download }}" />
<param name="onError" value="onErrorHandler" />
<param name="onResize" value="onResizeHandler" />
<a href="http://go.microsoft.com/fwlink/?LinkID=108182">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" />
</a>
</object>
<iframe style="visibility: hidden; height: 0; width: 0; border: 0px;"></iframe>
{% endif %}
{% endautoescape %}
</div>
{% endspaceless %}
{% endif %}
{% endblock %}
{% block ezobjectrelationlist_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
<ul {{ block( 'field_attributes' ) }}>
{% for contentId in field.value.destinationContentIds if parameters.available[contentId] %}
{{ fos_httpcache_tag('relation-' ~ contentId) }}
<li>
{{ render( controller( "ez_content:viewAction", {'contentId': contentId, 'viewType': 'embed', 'layout': false} ) ) }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endspaceless %}
{% endblock %}
{# @todo:
# - add translate filter
#}
{% block ezgmaplocation_field %}
{##
# This field type block accepts the following parameters:
# - boolean showMap whether to show the map or not, default is true
# - boolean showInfo whether to show the latitude, longitude and address or not, default is true
# - integer zoom the default zoom level, default is 13
# - boolean draggable whether to enable or not draggable map (useful on mobile / responsive layout), default is true
# - string|false width the width of the rendered map with its unit (ie "500px" or "50em"),
# set to false to not set any width style inline, default is 500px
# - string|false height the height of the rendered map with its unit (ie "200px" or "20em"),
# set to false to not set any height style inline, default is 200px
# - boolean scrollWheel If false, disables scrollwheel zooming on the map. Enabled by default.
#
# For further reading:
# - https://wiki.openstreetmap.org
# - http://leafletjs.com/reference-1.3.0.html
#}
{% spaceless %}
<div {{ block( 'field_attributes' ) }}>
{% set defaultWidth = '500px' %}
{% set defaultHeight = '200px' %}
{% set defaultShowMap = true %}
{% set defaultShowInfo = true %}
{% set defaultDraggable = 'true' %}
{% set defaultScrollWheel = 'true' %}
{% set hasContent = field.value is not null %}
{% set latitude = field.value.latitude %}
{% set longitude = field.value.longitude %}
{% set address = field.value.address|default( "" ) %}
{% set mapId = "maplocation-map-" ~ field.id %}
{% set defaultZoom = latitude is null and longitude is null ? 1 : 15 %}
{% set zoom = parameters.zoom|default( defaultZoom ) %}
{% set mapWidth, mapHeight = defaultWidth, defaultHeight %}
{% if parameters.width is defined %}
{% set mapWidth = parameters.width %}
{% endif %}
{% if parameters.height is defined %}
{% set mapHeight = parameters.height %}
{% endif %}
{% set showMap = defaultShowMap %}
{% if parameters.showMap is defined and not parameters.showMap %}
{% set showMap = false %}
{% endif %}
{% set showInfo = defaultShowInfo %}
{% if parameters.showInfo is defined and not parameters.showInfo %}
{% set showInfo = false %}
{% endif %}
{% set draggable = defaultDraggable %}
{% if parameters.draggable is defined and not parameters.draggable %}
{% set draggable = 'false' %}
{% endif %}
{% set scrollWheel = defaultScrollWheel %}
{% if parameters.scrollWheel is defined and not parameters.scrollWheel %}
{% set scrollWheel = 'false' %}
{% endif %}
{% if showInfo %}
<dl>
<dt>Latitude</dt>
<dd>{{ latitude is not null ? latitude : 'content-field.latitude.not_set'|trans|desc("Not set") }}</dd>
<dt>Longitude</dt>
<dd>{{ longitude is not null ? longitude : 'content-field.longitude.not_set'|trans|desc("Not set") }}</dd>
{% if address %}
<dt>Address</dt>
<dd>{{ address }}</dd>
{% endif %}
</dl>
{% endif %}
{% if hasContent and showMap %}
{% set latitude = latitude|default(0) %}
{% set longitude = longitude|default(0) %}
<script>
if (typeof(window.ezgmaplocationMapsScriptLoaded) == 'undefined') {
(function (win, doc) {
var myScript = document.createElement('script');
var myCss = document.createElement('link');
myScript.src = 'https://unpkg.com/leaflet@1.3.1/dist/leaflet.js';
myCss.rel = "stylesheet";
myCss.href = "https://unpkg.com/leaflet@1.3.1/dist/leaflet.css";
win.ezgmaplocationMapsScriptLoaded = true;
doc.body.appendChild(myCss);
doc.body.appendChild(myScript);
})(window, document)
}
</script>
<script type="text/javascript">
(function (win) {
var mapView = function (mapId, latitude, longitude) {
var coordinates = [latitude, longitude];
var mapConfig = {
dragging: {{ draggable }},
scrollWheelZoom: {{ scrollWheel }},
zoom: {{ zoom }},
center: coordinates
};
var map = L.map(mapId, mapConfig);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker(coordinates).addTo(map);
};
win.addEventListener(
'load',
function () {
mapView("{{ mapId }}", {{ latitude }}, {{ longitude }});
},
false
);
})(window);
</script>
{% set mapStyle = mapWidth ? "width:" ~ mapWidth ~ ";": "" %}
{% set mapStyle = mapHeight ? mapStyle ~ " height:" ~ mapHeight : mapStyle %}
<div class="maplocation-map" id="{{ mapId }}" style="{{ mapStyle }}"></div>
{% endif %}
</div>
{% endspaceless %}
{% endblock %}
{# This field accepts the following parameters:
# - alias (image variation name). Defaults to "original" (e.g. image originally uploaded)
# - parameters.width. Allows forcing width of the image in the HTML
# - parameters.height. Allows forcing height of the image in the HTML
# - parameters.class. Allows setting CSS custom class name for the image
#}
{% block ezimage_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
<figure {{ block( 'field_attributes' ) }}>
{% set imageAlias = ez_image_alias( field, versionInfo, parameters.alias|default( 'original' ) ) %}
{% set src = imageAlias ? asset( imageAlias.uri ) : "//:0" %}
{% set attrs = {
class: parameters.class|default(''),
height: parameters.height is defined ? parameters.height : (imageAlias ? imageAlias.height : ''),
width: parameters.width is defined ? parameters.width : (imageAlias ? imageAlias.width : ''),
} %}
{% if parameters.ezlink|default({}) is not empty %}
<a
href="{{ parameters.ezlink.href }}"
{% if parameters.ezlink.title is defined %} title="{{ parameters.ezlink.title|e('html_attr') }}"{% endif %}
{% if parameters.ezlink.target is defined %} target="{{ parameters.ezlink.target|e('html_attr') }}"{% endif %}
>
{% endif %}
<img src="{{ src }}" alt="{{ parameters.alternativeText|default(field.value.alternativeText) }}" {% for attrname, attrvalue in attrs if attrvalue %}{{ attrname }}="{{ attrvalue }} " {% endfor %}/>
{% if parameters.ezlink|default({}) is not empty %}
</a>
{% endif %}
</figure>
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezimageasset_field %}
{% spaceless %}
{% if not ez_is_field_empty(content, field) and parameters.available %}
{{ fos_httpcache_tag('relation-' ~ field.value.destinationContentId) }}
<div {{ block('field_attributes') }}>
{{ render(controller('ez_content:embedAction', {
contentId: field.value.destinationContentId,
viewType: 'asset_image',
noLayout: true,
params: {
parameters: parameters|default({'alias': 'original'})|merge({'alternativeText': field.value.alternativeText })
}
}))}}
</div>
{% endif %}
{% endspaceless %}
{% endblock %}
{% block ezobjectrelation_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) and parameters.available %}
{{ fos_httpcache_tag('relation-' ~ field.value.destinationContentId) }}
<div {{ block( 'field_attributes' ) }}>
{{ render( controller( "ez_content:viewAction", {'contentId': field.value.destinationContentId, 'viewType': 'text_linked', 'layout': false} ) ) }}
</div>
{% endif %}
{% endspaceless %}
{% endblock %}
{# pageService is exposed under parameters.pageService thanks to Page\ParameterProvider #}
{% block ezpage_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
{% set layout = field.value.page.layout %}
{% set template = parameters.pageService.getLayoutTemplate( layout ) %}
{% include template with { 'zones': field.value.page.zones, 'zone_layout': layout, 'pageService': parameters.pageService } %}
{% endif %}
{% endspaceless %}
{% endblock %}
{# The simple_block_field block is a shorthand html block-based fields (like eztext or ezrichtext) #}
{# You can define a field_value variable before rendering this one if you need special operation for rendering content (i.e. nl2br) #}
{% block simple_block_field %}
{% spaceless %}
{% if field_value is not defined %}
{% set field_value = field.value %}
{% endif %}
<div {{ block( 'field_attributes' ) }}>
{% endspaceless %}{{ field_value|raw }}{% spaceless %}
</div>
{% endspaceless %}
{% endblock %}
{% block simple_inline_field %}
{% spaceless %}
{% if field_value is not defined %}
{% set field_value = field.value %}
{% endif %}
<span {{ block( 'field_attributes' ) }}>{{ field_value }}</span>
{% endspaceless %}
{% endblock %}
{# Block for field attributes rendering. Useful to add a custom class, id or whatever HTML attribute to the field markup #}
{% block field_attributes %}
{% spaceless %}
{% set attr = attr|default( {} ) %}
{% for attrname, attrvalue in attr %}{{ attrname }}="{{ attrvalue }}" {% endfor %}
{% endspaceless %}
{% endblock %}
You can’t perform that action at this time.