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 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,
@piotrpog
piotrpog / pagination_ellipsis.twig
Last active Jun 7, 2019
Pagination template component for Craft CMS. Excessive links are replaced by elipsis. More info: http://craftsnippets.com/articles/ellipsis-pagination-component-for-craft-cms
View pagination_ellipsis.twig
{# v2 #}
{# http://craftsnippets.com/articles/ellipsis-pagination-component-for-craft-cms #}
{# requires pageInfo variable #}
{# settings #}
{% set neighbours = 1 %}
{# symbols #}
{% set prev = '❮' %}
{% set next = '❯' %}
View breadcrumb.twig
{# v2 #}
{# http://craftsnippets.com/articles/breadcrumb-created-from-url-for-craft-cms #}
{# settings #}
{% set nonElementLinks = false %}
{# populate breadcrumbLinks array if no array of links was provided #}
{% if breadcrumbLinks is not defined %}
{% set breadcrumbLinks = [] %}
{# home #}
@piotrpog
piotrpog / quick_edit.twig
Last active Jun 7, 2019
Quick edit link component for Craft CMS. More info on http://craftsnippets.com/articles/quick-edit
View quick_edit.twig
{# v2 #}
{# http://craftsnippets.com/articles/quick-edit #}
{% if currentUser and currentUser.can('accessCp') and not craft.app.request.isLivePreview %}
{% if (entry is defined and entry.isEditable) or (category is defined and category.isEditable) %}
<div class="edit-button">
<a href="{{ entry.getCpEditUrl() ?? category.getCpEditUrl() }}" target="_blank" class="button is-info">
{{'edit'|t}}
</a>
</div>
{% 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
@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 %}
@piotrpog
piotrpog / emailLinks.twig
Created Apr 25, 2019
Twig macro converting email addresses in text into links secured from spambots. More info: http://craftsnippets.com/articles/converting-email-addresses-into-links-using-twig-macro
View emailLinks.twig
@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>
View element-api.php
<?php
use craft\elements\Entry;
return [
'endpoints' => [
'search.json' => function() {
// settings
$section_handle = 'articles';
$phrase = Craft::$app->request->getParam('query');
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">
You can’t perform that action at this time.