Skip to content

Instantly share code, notes, and snippets.

{# 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 / svg_macro.twig
Last active February 7, 2021 19:46
Twig macro that loads and processes SVG image. More info: http://craftsnippets.com/articles/working-with-svg-images-in-craft-cms-templates
{%- macro svg(path, attributes = null, alt = null) -%}
{# v1 #}
{# settings #}
{% set directory = 'svg' %}
{# logic #}
{% if path is defined and path is not empty %}
{% set svg = svg('@webroot/'~directory~'/'~path~'.svg', namespace=true) %}
{% if alt %}
{% set svg = svg|prepend('<title>'~alt~'</title>') %}
{% endif %}
{# v6 #}
{# USAGE:
{% embed '_components/modal' with {
modalHandle: 'exampleHandle'
} %}
{% block modalContent %}
SOMETHING INSIDE
{% endblock %}
{% endembed %}
#}
[data-neo-b].blocktype{
font-size: 1.1rem;
background-color: #03A9F4;
color: white;
padding-left: 3rem !important;
padding-right: 3rem !important;
}
.ni_block{
border: 2px solid rgb(3 169 244 / 50%) !important;
@piotrpog
piotrpog / breadcrumb_seomatic.twig
Last active August 15, 2020 11:18
Breadcrumb template component for Craft CMS based on Seomatic plugin. More info on http://craftsnippets.com/articles/breadcrumb-created-from-url-for-craft-cms
{% v2 %}
% 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 / breadcrumb.twig
Last active August 15, 2020 11:18
Breadcrumb template component for Craft CMS. More info on http://craftsnippets.com/articles/breadcrumb-created-from-url-for-craft-cms
{# v4 #}
{# 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 #}
<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'),
}) }}
@piotrpog
piotrpog / svg_map.twig
Last active August 5, 2020 03:21
SVG map-based navigation for Craft CMS. More info: http://localhost/_pog/craft-snippets-craft/web/articles/creating-map-based-navigation-in-craft-cms
{# 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]) %}
@piotrpog
piotrpog / gist:5c34d9de9b167dc2edca52ea2db7efdb
Created August 3, 2020 06:47
Craft CMS Verbb Navigation - URL stucture based on menu structure
{{ craft.navigation.nodes().ancestorOf( craft.navigation.nodes('test').all()|filter(x => x.element.id == id)|first.id ).ancestorDist(1).one().element.uri ?? null }}/{{slug}}
@piotrpog
piotrpog / link_list_macro.twig
Created June 29, 2020 08:04
Twig macro generating links from array of entries