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
{% apply spaceless %} | |
{# lightswitch field values #} | |
{% if lighswitchOn is not defined %} | |
{% set lighswitchOn = 'yes' %} | |
{% endif %} | |
{% if lighswitchOff is not defined %} | |
{% set lighswitchOff = 'no' %} | |
{% 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
{%- macro transformOrPlaceholder(image, settings, attributes = {}) -%} | |
{% if image is not null %} | |
{% set src = image.getUrl(settings) %} | |
{% set attributes = attributes|merge({src: src}) %} | |
{{tag('img', attributes)}} | |
{% elseif settings.width is defined or settings.height is defined %} | |
{% set width = settings.width ?? settings.height %} | |
{% set height = settings.height ?? settings.width %} | |
{% set src = 'https://placehold.co/'~width~'x'~height %} | |
{% set attributes = attributes|merge({src: src}) %} |
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
// place this code in module variable file | |
public $userFieldHandle = 'visitedarticles'; | |
public $categoryFieldHandle = 'articleCategory'; | |
public function saveArticleVisit($article){ | |
$user = Craft::$app->getUser()->getIdentity(); | |
if(!is_null($user)){ |
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
'components' => [ | |
'log' => function() { | |
$config = craft\helpers\App::logConfig(); | |
if ($config) { | |
$config['targets'][0]['includeUserIp'] = false; | |
$config['targets'][0]['logFile'] = '@storage/logs/web.log'; | |
$config['targets'][0]['enableRotation'] = true; | |
$config['targets'][0]['maxFileSize'] = 10240; | |
$config['targets'][0]['maxLogFiles'] = 5; | |
$config['targets'][0]['levels'] = ['error', 'warning']; |
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
use craft\mail\Message; | |
$settings = Craft::$app->systemSettings->getSettings('email'); | |
$message = new Message(); | |
$message->setFrom([$settings['fromEmail'] => $settings['fromName']]); | |
$message->setTo('xx@x.x'); | |
$message->setHtmlBody('test body'); | |
$message->setSubject('test subject'); | |
Craft::$app->mailer->send($message); |
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 jsVar(variable, jsVariableName) %} | |
{# v1 #} | |
var {{jsVariableName}} = {{variable|json_encode|raw}}; | |
{% 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
{# 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
{# 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
{% 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> |