Skip to content

Instantly share code, notes, and snippets.

piotrpog

Block or report user

Report or block piotrpog

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@piotrpog
piotrpog / svg_map.twig
Last active Mar 29, 2020
SVG map-based navigation for Craft CMS. More info: http://localhost/_pog/craft-snippets-craft/web/articles/creating-map-based-navigation-in-craft-cms
View svg_map.twig
{# settings #}
{% set map = include('usa.svg') %}
{% set mapLinks = entry.mapLinks.all() %}
{# logic #}
{% set map = map|retconRemove('style') %}
{% set regionsUsed = [] %}
{% for link in mapLinks %}
{% if link.linkRegion is not empty and link.linkEntry.exists() and link.linkRegion not in regionsUsed %}
{% set regionsUsed = regionsUsed|merge([link.linkRegion]) %}
View placeholder_service.twig
{%- 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}) %}
View dynamic_pagination.twig
{# v2 #}
{% if pagination_list is defined %}
{% js %}
// AJAX REQUEST DATA
{% set current_url = craft.request.getRequestUri()|split(craft.request.getPath())[0]~craft.request.getPath() %}
{% set ajax_data = {
current_url: current_url,
pagination_list: pagination_list|hash,
pagination_parameters: pagination_parameters ?? null,
View contact_form.twig
<form class="js-contact-form">
<fieldset class="js-contact-form-fieldset">
{{ csrfInput() }}
<div class="field">
{{tag('label', {
for: 'form-email',
class: 'label',
text: 'Your Email'|t('contact-form'),
}) }}
View gist:9fcc6b6bb5b838d64ed5075003d2f820
// 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)){
@piotrpog
piotrpog / gist:6da736ead280bd9989173cad05e6ebef
Created Nov 21, 2019
Craft CMS log only warning and errors
View gist:6da736ead280bd9989173cad05e6ebef
'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'];
@piotrpog
piotrpog / footer_creator.twig
Last active Nov 18, 2019
Email footer creator made with Craft CMS.
View footer_creator.twig
View _article.twig
{% if article is defined %}
<li>
{{article.id}} - {{article.title}}
</li>
{% endif %}
View gist:e63877567d82d423d34951e37b29a6ad
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);
View js_var.twig
{% macro jsVar(variable, jsVariableName) %}
{# v1 #}
var {{jsVariableName}} = {{variable|json_encode|raw}};
{% endmacro %}
You can’t perform that action at this time.