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
View gist:a7e56ea2713ea5d0fab451c3e282ecfd
var gulp = require('gulp');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
const notifier = require('node-notifier');
gulp.task('dev', ['sass:development', 'watch:development', 'browser-sync']);
gulp.task('default', ['dev']);
View Twig truncate macro
{% macro truncate(text, limit, append) %}
{# settings #}
{% set suffix = append|default('...') %}
{% set punctuation = ['.',',','-',':',';'] %}
{# logic #}
{% set array = text|split(' ') %}
{% set arrayTruncated = array|slice(0, limit) %}
{% set string = arrayTruncated|join(' ') %}
{% if limit and array|length > limit %}
{% for mark in punctuation %}
@piotrpog
piotrpog / searchit_category_filter.twig
Last active Feb 28, 2019
Category filter for Craft Cms searchit plugin. Takes nesting of categories into account. More information on http://craftsnippets.com/articles/filtering-entries
View searchit_category_filter.twig
{% set handle = 'category_handle' %}
{% for category in craft.categories.group(handle).all() %}
{% set line = '' %}
{% set depth = category.getAncestors()|length %}
{% for number in range(0, depth) %}
{% set line = line ~ '=' %}
{% endfor %}
{{ ({
filter: {
relatedTo: category.id
@piotrpog
piotrpog / Craft CMS - URL macro
Last active Mar 4, 2019
This macro fetches routes into Twig template. More info on http://craftsnippets.com/articles/url-macro
View Craft CMS - URL macro
{# v2 #}
{% macro url(routeName, tokens) %}
{% spaceless %}
{% set keyword = 'name' %}
{% set routeString = null %}
{% for route, routeSettings in craft.app.routes.getConfigFileRoutes %}
{% if routeSettings[keyword] is defined and routeSettings[keyword] == routeName %}
{% set routeString = route %}
{% endif %}
View app.php
<?php
return [
'components' => [
'mailer' => function() {
$settings = \craft\helpers\App::mailSettings();
$settings->transportType = \craft\mail\transportadapters\Smtp::class;
$settings->transportSettings = [
'useAuthentication' => true,
'host' => getenv('SMTP_HOST'),
'port' => getenv('SMTP_PORT'),
View feed.rss
{% spaceless %}
{# settings #}
{% set title = siteName %}
{% set channelDescription = 'description' %}
{% set descriptionHandle = 'intro' %}
{% set items = craft.entries.section('articles').limit(50) %}
{# feed #}
{% if craft.app.request.segments|last == _self %}
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
View element-api.php
<?php
use craft\elements\Entry;
return [
'endpoints' => [
'search.json' => function() {
// settings
$section_handle = 'articles';
$phrase = Craft::$app->request->getParam('query');
@piotrpog
piotrpog / breadcrumb_seomatic.twig
Last active Apr 14, 2019
Breadcrumb template component for Craft CMS based on Seomatic plugin. More info on http://craftsnippets.com/articles/breadcrumb-created-from-url-for-craft-cms
View breadcrumb_seomatic.twig
{% v1 %}
% set breadcrumbLinks = seomatic.jsonLd.get('breadcrumbList').itemListElement %}
{% if breadcrumbLinks|length > 1 %}
<nav class="breadcrumb" aria-label="{{'breadcrumbs'|t}}">
<ul>
{% for link in breadcrumbLinks %}
<li class="{{loop.last ? 'is-active'}}" {{loop.last ? 'aria-current="page"'}}>
<a href="{{ link.item['@id'] }}">
<span itemprop="name">{{ link.item['name'] }}</span>
@piotrpog
piotrpog / pagination_select.twig
Created May 10, 2019
Pagination template component for Craft CMS. List of pages is rendered using <select> HTML element. More info: http://craftsnippets.com/articles/ellipsis-pagination-component-for-craft-cms
View pagination_select.twig
{# settings #}
{% set info = pageInfo %}
{# logic #}
{% if info.totalPages > 1 %}
<select name="" id="" onchange="document.location.href = this.options[this.selectedIndex].value;">
{% for link in info.getRangeUrls( 1, info.totalPages ) %}
<option value="{{link}}" {{info.currentPage == loop.index ? 'selected="selected"'}}>{{'page'|t}} {{loop.index}}</option>
{% endfor %}
</select>
{% endif %}
View disqus.twig
{% set shortname = 'YOUR_WEBSITE_SHORTNAME' %}
{% if entry is defined %}
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = '{{entry.url}}';
this.page.identifier = '{{entry.id}}';
this.page.title = '{{entry.title}}';
};
(function() { // DON'T EDIT BELOW THIS LINE
You can’t perform that action at this time.