Skip to content

Instantly share code, notes, and snippets.

View terryupton's full-sized avatar

Terry Upton terryupton

View GitHub Profile
@terryupton
terryupton / Tailwind Clamp and Text Size using Arbitary values or CSS.html
Created April 15, 2025 17:03
How to use clamp for text/font sizes usaing Tailwind arbitary values and CSS eqivilents
<h1 class="text-[clamp(var(--text-4xl),_12vw,_var(--text-8xl))]">
Heading
</h1>
<h1 class="text-[clamp(var(--text-3xl),_10vw,_var(--text-6xl))]">
Heading
</h1>
@terryupton
terryupton / cache-bust-pending.twig
Created April 15, 2025 08:08
How to cache bust in Craft CMS based on pending posts/dates.
{# Fetch the next **pending** entry due to go live #}
{% set nextToCome = craft.entries()
.section('articles')
.status('pending')
.orderBy('postDate asc')
.one() %}
{# If there is no entry due to go live, cache the fragment for a year (change to what you need) #}
{% set cacheExpiry = nextToCome ? nextToCome.postDate : now|date_modify('+1 year') %}
@terryupton
terryupton / Image Reset CSS.css
Last active April 15, 2025 10:22
Image Reset CSS
img {
max-width: 100%;
height: auto;
vertical-align: middle;
font-style: italic;
background-repeat: no-repeat;
background-size: cover;
shape-margin: 0.75rem;
}
<!-- Center icons on list items in tailwind when list items span more than one line -->
<!-- https://www.youtube.com/watch?v=5QTHG99OYS4&ab_channel=TailwindLabs -->
<!-- https://play.tailwindcss.com/aUGlnWcFpY -->
<!-- sets the item to 1lh line-height unit (https://caniuse.com/?search=lh%20unit) -->
<ul role="list" class="mt-10 space-y-3 text-sm/6 text-gray-600">
<li class="flex items-start gap-x-3">
<svg class="h-[1lh] w-5 flex-none fill-indigo-600" viewBox="0 0 20 20" aria-hidden="true">
<path fill-rule="evenodd" d="M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z" clip-rule="evenodd" />
</svg>
@terryupton
terryupton / tailwind-concentric-border-radius.html
Last active April 13, 2025 15:58
Concentric border-radius with tailwind and css vars
<!-- Concentric border-radius with tailwind -->
<!-- https://www.youtube.com/watch?v=X3-4jwm4Z4Y&ab_channel=TailwindLabs -->
<!-- https://play.tailwindcss.com/SIHJT7S215 -->
<!--
The Calculation
The the parent border radius and subtract the padding adn this gives you the _child_ border radius.
E.G
parent = 2rem (32px)
padding = 0.75rem (12px)
@terryupton
terryupton / character-count-ckeditor-craftcms.md
Created March 22, 2025 10:34
Adding character count to CKEditor in Craft CMS

The first-party WordCount plugin is already included in Craft’s CKEditor plugin. It can show word and/or character counts and include logic on what should happen as you type (e.g. when you get near or over the limit). If you toggle “Show word count” in the CKEditor field’s setting, you get the word count shown underneath the field. To turn on character count, go to CKEditor Config used by that field and add the following under “Config Options”:

"wordCount": {
    "displayCharacters": true,
    "displayWords": true
}
@terryupton
terryupton / status-history.twig
Created February 1, 2022 11:01
Order Status History Craft Commerce
<h3 class="font-semibold mb-3 text-xl">
{{- 'Status History'|t -}}
</h3>
<ol class="space-y-5 text-sm">
{% for history in order.histories %}
<li>
<h5 class="mb-1 inline-block uppercase text-11 border px-1 py-0.5 leading-none text-{{ history.newStatus.color }}-500 border-{{ history.newStatus.color }}-500">
{{- history.newStatus -}}
</h5>
<div class="ml-2">
@terryupton
terryupton / .htaccess
Created December 22, 2021 15:53
HTAccess for Craft Sites 2021
<IfModule mod_rewrite.c>
# ------------------------------------------------------------------------------
# | Exclude directories from the rewrite rules |
# ------------------------------------------------------------------------------
# RewriteRule ^eShots - [L]
# ------------------------------------------------------------------------------
# | Rewrite engine |
# ------------------------------------------------------------------------------
# Turning on the rewrite engine and enabling the `FollowSymLinks` option is
@terryupton
terryupton / craft-updates-to-index.md
Last active December 22, 2021 10:54
Remember to check and update craft index.php and craft files on a regular basis!

Updating vlucas/phpdotenv on 22 December 2021

Wow! So I never knew this...and perhaps it's just me but thought I should put it out there....so I have upgraded to "vlucas/phpdotenv": "^5.4.0" as it seems all of my projects were still on ^2.4.0. What I never realised is that we should also be maintaining the index.php file and the craft files too. As these don't fall into the regular craft updates.

So today, I have just updated the index.php added the new bootstrap.php file and also updated the craft file too - so these all work with "vlucas/phpdotenv": "^5.4.0"

I must ensure I look out for updates on these files in the future. Perhaps everyone already knows this, but I never did until now. 😳

{% set checkboxFieldClasses =
"form-checkbox w-5 h-5 text-green-500" %}
{% if field.type == "checkbox_group" %}
{% set fieldClass = checkboxFieldClasses %}
<div class="mb-2">
{% include 'forms/_default/_partials/_label.twig' %}
{{ field.oneLine ? '<div class="flex flex-wrap">'|raw }}