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 phoneNumber(phoneNumber) %} | |
<a href="tel:{{ phoneNumber|replace({'-':'', ' ':'', '.':'', '(':'', ')':''}) }}">{{ phoneNumber }}</a> | |
{% endmacro %} |
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 readTime(text) %} | |
{% spaceless %} | |
{# v1 #} | |
{# settings #} | |
{% set wordsPerMinute = 265 %} | |
{% set showLessThanMinute = true %} | |
{# logic #} | |
{% set plaintext = text|striptags|replace({'—': ' ', '–': ' ', '-': ' ', '\n': ' '}) %} | |
{% set words = plaintext|split(' ') %} | |
{% set minutes = ceil(words|length / wordsPerMinute) %} |
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
{# v3 #} | |
{# http://craftsnippets.com/articles/ellipsis-pagination-component-for-craft-cms #} | |
{# requires pageInfo variable #} | |
{# settings #} | |
{% set neighbours = 1 %} | |
{# symbols #} | |
{% set prev = '❮' %} | |
{% set next = '❯' %} |
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 ') %} |
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
<?php | |
use craft\elements\Entry; | |
return [ | |
'endpoints' => [ | |
'search.json' => function() { | |
// settings | |
$section_handle = 'articles'; | |
$phrase = Craft::$app->request->getParam('query'); |
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
{%- 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
{% 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> |