This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# v1 #} | |
{# settings #} | |
{% set faviconFileName = '/static/images/favicon.jpg' %} | |
{% set sizesIcon = [192, 48, 32, 16] %} | |
{% set sizesAppleTouch = [180] %} | |
{# output #} | |
{% if craft.app.plugins.isPluginEnabled('imager') and craft.imager.transformImage(faviconFileName, {}, null, {suppressExceptions : true}) %} | |
{% for faviconSize in sizesIcon %} | |
{% set faviconTransform = { | |
width: faviconSize, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if craft.app.urlManager.matchedElement and craft.app.urlManager.matchedElement.uri == '__home__' %} | |
{% set seoTitle = craft.app.urlManager.matchedElement.title %} | |
{% elseif craft.app.urlManager.matchedElement %} | |
{% set seoTitle = craft.app.urlManager.matchedElement.title ~ ' - ' ~ siteName %} | |
{% else %} | |
{% set seoTitle = siteName %} | |
{% endif %} | |
<title>{{ seoTitle }}</title> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- macro timeAgo(date, additionalAttributes) -%} | |
{# v1 #} | |
{% if date is defined %} | |
{# settings #} | |
{% set format = 'medium' %} | |
{% set locale = currentSite.language %} | |
{# logic #} | |
{% set formatter = create({ class: 'craft\\i18n\\Formatter', locale: locale }) %} | |
{% set attributes = { | |
text: formatter.asRelativeTime(date), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- macro defaultDateFormat(date, additionalAttributes) -%} | |
{# v1 #} | |
{% if date is defined %} | |
{# settings #} | |
{% set format = 'medium' %} | |
{# logic #} | |
{% set attributes = { | |
text: date|date(format), | |
datetime: date|date('yy-m-d') | |
} %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- macro svg(path, attributes = null, alt = null) -%} | |
{# v1 #} | |
{# settings #} | |
{% set directory = 'svg' %} | |
{# logic #} | |
{% if path is defined and path is not empty %} | |
{% set svg = svg('@webroot/'~directory~'/'~path~'.svg', namespace=true) %} | |
{% if alt %} | |
{% set svg = svg|prepend('<title>'~alt~'</title>') %} | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# v2 #} | |
{%- macro ytIframe(html, lazy = true) -%} | |
{% if html is not empty and craft.app.plugins.isPluginEnabled('retcon') %} | |
{% set html = html|retconAttr('iframe', {'style' : 'position: absolute; top: 0; left: 0; width: 100%; height: 100%;'} ) %} | |
{% if lazy %} | |
{% set html = html|retconAttr('iframe', {'loading' : 'lazy'} ) %} | |
{% endif %} | |
{% set html = html|retconWrap( [ 'iframe' ], 'figure') %} | |
{% set html = html|retconAttr('figure', {'style' : 'position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; margin: 0px;'} ) %} | |
{% set html = html|retconWrap( [ 'figure' ], 'div.youtube-player') %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# v2 #} | |
{%- macro ytAddress(url, lazy = true) -%} | |
{% if url is not empty %} | |
{% set id = url|split('v=')|last %} | |
{% set id = id|split('&')|first %} | |
{% set id = id|split('/')|last %} | |
<div class="youtube-player"> | |
<figure style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; margin: 0px;"> | |
<iframe src="https://www.youtube.com/embed/{{id}}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"{{ lazy ? ' loading="lazy"'}}></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# requires global with handle 'favicon' containing asset field with handle 'faviconFile' #} | |
{# v2 #} | |
{% cache globally %} | |
{% set sizesIcon = [192, 48, 32, 16] %} | |
{% set sizesAppleTouch = [180] %} | |
{% if favicon is defined and favicon['faviconFile'] is defined and favicon.faviconFile.exists() and favicon.faviconFile.one().kind == 'image' %} | |
{# link icon #} | |
{% for faviconSize in sizesIcon %} | |
{% set icon = favicon.faviconFile.one() %} | |
{% set shorterEdge = icon.width > icon.height ? icon.height : icon.width %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# v1 #} | |
{% macro truncateChars(text, limit, suffix) %} | |
{% spaceless %} | |
{# settings #} | |
{% set defaultSuffix = '...' %} | |
{# logic #} | |
{% if text and limit %} | |
{% set text = text|striptags %} | |
{% set suffix = suffix|default(defaultSuffix) %} | |
{% set stringy = create( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# v1 #} | |
{% macro truncateWords(text, length, suffix) %} | |
{% spaceless %} | |
{# settings #} | |
{% set defaultSuffix = '...' %} | |
{# logic #} | |
{% if text and length %} | |
{% set suffix = suffix|default(defaultSuffix) %} | |
{% set text = text|striptags %} | |
{% set text = text|replace('/\\n/', '\n ') %} |