Skip to content

Instantly share code, notes, and snippets.

@watershed
watershed / allFields.twig
Last active May 3, 2024 16:37
Report all fields in a Craft instance
{% set fields = craft.app.fields.allFields() %}
{# Dependencies:
Use of `return`ing variables in macros, courtesy of Marion Newlevant's Twig Perversion:
https://plugins.craftcms.com/twig-perversion
#}
<style>
body {color: #333; font: 1rem/1.25 system-ui, sans-serif; margin: 2rem;}
table {border-collapse: collapse;}
@watershed
watershed / lrno-schema.html
Last active March 11, 2024 14:43
Laura Ritchie note options (lrno)
<!-- Within the source code view of a WordPress post body -->
<style>
/* CSS for the `lrno` namespace to be provided and inserted here */
</style>
<!-- Hidden after successful JavaScript outcome -->
<div class="lrno-path">/path/to/assets/here</div>
<!-- Hidden after successful JavaScript outcome -->
@watershed
watershed / vimeo-embed-url.html
Last active September 24, 2021 14:10
Vimeo embedding
<!-- Historically, Vimeo URLs of the following form would work as a straightforward `src` attribute value on an iframe -->
<iframe src="https://player.vimeo.com/video/123456789" width="X" height="Y" allowfullscreen></iframe>
<!-- At some point in September 2021 Vimeo changed this, so that URLs require an `h` parameter to work -->
<iframe src="https://player.vimeo.com/video/123456789?h=8yt65b2a98" width="X" height="Y" allowfullscreen></iframe>
<!--
In the above examples:
{#####
For a `body` field with type:fieldHandles structure:
collStart: collId*, attr
subheading: text*, customId, hWrap, incToC
text: text*
quote: text*, cite, citeUrl
images images* (needs work)
video: videoUrl*,ratio
collEnd collId*
@watershed
watershed / dateTimeMacro.twig
Last active July 2, 2021 10:31
CraftCMS datetime macro
{#
value : date and/or time value validated as not null (mandatory),
format : php date format string (mandatory),
options: {
prefix: string to append to processed format,
suffix: string to append to processed format,
tag : html tagname string,
html : markup, typically to be wrapped in a <time> element,
attr : hash of name:value attribute pairs
}
@watershed
watershed / rename-files-in-folder-to-all-lowercase.sh
Created June 19, 2018 16:42
Rename files in folder to all lowercase
for f in *; do mv "$f" "$f.tmp"; mv "$f.tmp" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done
@watershed
watershed / update-multiple-rows-same-column.sql
Created June 14, 2018 08:54
MySQL: update multiple rows for the same column/field
UPDATE table_name
SET field_to_update = CASE id
WHEN n THEN 'Text value'
END
WHERE id IN (n)
@watershed
watershed / select-files-from-list.scpt
Created June 14, 2018 08:52
Select files from list AppleScript
set myValues to {"filename.ext", "filename.ext"}
tell application "Finder" to set fileList to files of target of front Finder window as alias list
set matchedFiles to {}
repeat with aFile in my fileList
repeat with aValue in myValues
tell application "System Events" to if aFile's name contains (contents of aValue) then set end of matchedFiles to (aFile as text)
end repeat
end repeat
@watershed
watershed / craft-instruction-links.js
Last active January 2, 2016 14:44
CraftCMS: force links in field instructions to open in a new window
@watershed
watershed / management-bios.html
Created October 6, 2011 12:26
Management styling in IE7
<!-- The nested structure is at present like this -->
<div class="panel vcard" id="[hcard-forename-surname]">
<div class="header">
<h2 class="fn h3">[Forename] [Surname]</h2>
<div class="title">[Job title]</div>
</div>
<div class="figure left1of3">
<img alt="[Forename] [Surname]" src="[image_url]" class="photo">
</div>
<div class="bio">