Default values for custom tag attributes do nothing?

I would like a custom tag with attributes that have a default value set if the attribute is not provided.

A very basic example would be a custom tag that renders out an inline SVG icon. It would be called like this

<icon:user> or like this <icon:user color="blue">

In the custom tag I have a cfparam set up that as far as I can tell should handle this

<cfparam name="attributes.color" type="text" default="currentColor" />

But when I try to access attributes.color in my code, I get this error:

key [COLOR] doesn't exist

If I dump the attributes scope, it’s empty.

I can resolve this by checking whether it exists and setting the default value in the code, but I could swear that setting a default attribute like this used to work. And jumping through hoops to have a default value seems counter productive.

I can only seem to find documentation about the CFC based implementation of custom tags for Lucee, which is really not what I’m after.

Any insights?

Oh damn, of course just after writing all that I found my error. I had the cfparam tag in no-mans-land right after the cfswitch tag, before the cfcase tag

Moving it to the top of the file (or inside the cfcase block) resolves the problem.

I’ll leave the thread for anyone else who happens to make such a dumb mistake haha.

2 Likes