Trying to set a default asset folder using Craft tags I'm trying to set a default asset folder for a field, as per the Craft docs on Dynamic Subfolder Paths.

I'm trying to set the asset path for each blog article to be /our-journal/{date}/{slug}, where date is the creation date of the article, falling back to today's date otherwise.

/our-journal/{ entry.dateCreated|date('Y-m') ?: now|dateCreated('Y-m') }/{ slug }


I'm getting an internal server error:


  Could not resolve the subpath “our-journal/{ entry.dateCreated|date('Y-m') ?: now|dateCreated('Y-m') }/{ slug }”.


I've tried using both single and double braces around the variables, as the docs are a bit ambiguous.
I had a stupid typo in my path, where instead of the date filter, I'd typed dateCreated:

/our-journal/{ entry.dateCreated|date('Y-m') ?: now|dateCreated('Y-m') }/{ slug }


Should be:

/our-journal/{ entry.dateCreated|date('Y-m') ?: now|date('Y-m') }/{ slug }


Which, with what I learnt about fallbacks (see below), can be shortened to:

/our-journal/{ entry.dateCreated|date('Y-m') }/{ slug }


And if you're doing this within a matrix field, the entry is referred to by owner - so you'd need:

/our-journal/{ owner.dateCreated|date('Y-m') }/{ owner.slug }/


Fallbacks

I also found that I didn't need to provide fallbacks for entry tags - I'd thought that I'd need to provide a fallback for when a new entry hasn't yet been saved (to stop it falling over on e.g. dateCreated).

It appears that Craft is clever enough to hold the image in some temporary store, then move it into the intended folder when the article is first saved.