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.

  • Is Asset field inside of a Matrix field?
    – Brad Bell
    Nov 1 '17 at 18:45
  • I've got the default path on two fields - one on the entry and one in a matrix field on the same entry type. As far as I can see, it's the field directly on the entry that is causing the issue (probably both are, but that one is hitting validation first). Nov 2 '17 at 9:06
  • Thanks for your help @BradBell, I found a stupid typo. Also found something interesting about how Craft handles asset uploads on unsaved entries - see my answer below. Nov 2 '17 at 10:07

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 }/


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.