Shortcodes
In hindsight the below is probably achievable with normal variable syntax (i.e. without .Scratch), but it works.
Since TailwindCSS is all about the ability to add & edit styles directly in the HTML, I wanted to create a shortcode that would generate different colored alerts without having to modify any CSS stylesheets. This was the result:
But of course I had to figure it out the long way, so the below method also works:
Basically the key/value pairs (type
& color
) are being assigned to a .Scratch key (alert
). The next part of the code iterates over the .Scratch key to retrieve the color
value associated with the inputted type
key.
I had to pull $index into its own variable because iterating over the .Scratch key directly resulted in errors.