Skip to content

Instantly share code, notes, and snippets.

@zizther
zizther / index.php
Created August 19, 2025 16:38
Craft CMS enforce structure
private const string HOME_SLUG = '__home__';
Event::on(Entry::class, Entry::EVENT_BEFORE_SAVE, function (Event $event) {
$element = $event->sender;
if ($element->section->handle !== 'pages') {
return;
}
if ($element->parentId === null && $element->slug !== self::HOME_SLUG) {
@zizther
zizther / index.txt
Created February 14, 2024 02:16
Flickity carousel same height slides fix
// If you need all your slides to have same height,
// add the CSS selector to your slider cells and use this code in your CSS:
// CSS
.carousel-cell {
display: flex;
align-items: stretch;
min-height: 100%;
}
.carousel .flickity-slider {
@zizther
zizther / countries.json
Created August 15, 2023 20:18
Countries array
[
{
"label": "Afghanistan",
"value": "af",
"default": false
},
{
"label": "Åland Islands",
"value": "ax",
"default": false
@zizther
zizther / countries.js
Created March 27, 2023 03:47
Countries with phone code, currency and continent in JS object
const countries = {
AF: {name: "Afghanistan",phone: 93,symbol: "؋",currency: "AFN",continent: "Asia",continent_code: "AS",alpha_3: "AFG"},
AX: {name: "Aland Islands",phone: 358,symbol: "€",currency: "EUR",continent: "Europe",continent_code: "EU",alpha_3: "ALA"},
AL: {name: "Albania",phone: 355,symbol: "Lek",currency: "ALL",continent: "Europe",continent_code: "EU",alpha_3: "ALB"},
DZ: {name: "Algeria",phone: 213,symbol: "دج",currency: "DZD",continent: "Africa",continent_code: "AF",alpha_3: "DZA"},
AS: {name: "American Samoa",phone: 1684,symbol: "$",currency: "USD",continent: "Oceania",continent_code: "OC",alpha_3: "ASM"},
AD: {name: "Andorra",phone: 376,symbol: "€",currency: "EUR",continent: "Europe",continent_code: "EU",alpha_3: "AND"},
AO: {name: "Angola",phone: 244,symbol: "Kz",currency: "AOA",continent: "Africa",continent_code: "AF",alpha_3: "AGO"},
AI: {name: "Anguilla",phone: 1264,symbol: "$",currency: "XCD",continent: "North America",continent_code: "NA",alpha_3: "AIA"},
@zizther
zizther / country-phone-codes.json
Last active March 27, 2023 03:32
Country phone codes with flag emoji in JSON format
[{
"name": "Afghanistan",
"dial_code": "+93",
"emoji": "🇦🇫",
"code": "AF"
},
{
"name": "Aland Islands",
"dial_code": "+358",
"emoji": "🇦🇽",
@zizther
zizther / index.php
Created January 26, 2023 17:21
Remove all versions of <br> tag
<?php
$str = 'A string with <br> tags. Lorem ipsum dolor <br/> Nullam id elementum nisl <br />at sagittis lorem.'
// Replace <br> <br/> and <br /> with a blank space
$str = preg_replace('#<br\s*/?>#i', ' ', $str);
echo $str;
@zizther
zizther / index.twig
Created April 9, 2021 02:43
Twig loop - loop index divisible by
{% for item in items %}
{% if loop.index0 is divisible by(2) %}
{% endif %}
{% endfor %}
{#
1st - returns false
2nd - returns true
3rd - returns false
4th - returns true
@zizther
zizther / index.js
Created March 19, 2021 12:51
Document ready and window scroll in vanilla JS
let scrollpos = window.scrollY;
// Document ready
document.addEventListener("DOMContentLoaded", () => {
// Window scroll
window.addEventListener('scroll', () => {
scrollpos = window.scrollY;
console.log(scrollpos);
});
@zizther
zizther / index.twig
Created February 4, 2021 01:38
sounds like & like in Craft CMS queries
{% set entry = craft.entries({
section: 'blog',
where: ['sounds like', 'title', 'too']
}).one() %}
{# returns: two #}
{% set entry = craft.entries({
section: 'blog',
where: ['like', 'title', 'rob']
@zizther
zizther / index.twig
Created January 27, 2021 17:30
Order entries by title without `A` or `The` being taken into account
{% set entries = craft.entries({
section: 'schoolsAndColleges',
orderBy: ("(CASE WHEN `title` LIKE 'The %' THEN SUBSTRING(`title`, 5) WHEN `title` LIKE 'A %' THEN SUBSTRING(`title`, 3) ELSE `title` END) asc"),
limit: 10,
}) %}