I'm having some difficulty with "Restrict uploads to a single folder?" option on an Assets entry field. I find that when I upload an asset into the field, the asset folder gets created as expected, but the asset does not end up in the folder.
For example, if the author is SomeAuthor, a folder called 'SomeAuthor' gets created in the correct location in the Asset Source using the following dynamic path, set in the field setting as mentioned above:
{% if owner is defined %}{owner.author.username}{% elseif author is defined %}{author.username}{% endif %}
I'm using this to allow me to re-use the field on Matrix and non-Matrix sections, but the point is that the folder is created successfully. What isn't so successful is that the file does not end up inside that folder, but in the root of my Asset Source. I've tried combinations of logging in as the specified author, removing all the assets from the site. Re-indexing etc. etc. all to no avail.
Perhaps I'm looking in the wrong place.
Does anyone have any experience trying to achieve what I'm attempting?
The general context is I have separate users on the system, each responsible for a "project" page, along with permissions to create 'articles' and 'events' in the respective sections/channels. I want to have one asset folder per user, so that no matter where they upload assets, the assets end up in the same folder per user, so that user with username 'SomeAuthor's assets will end up in 'SomeAuthor' folder within my single site source. I am attempting to do this using this snippet above, which in theory should work considering the author.username is not changing...
EDIT
Since posting this, I have discovered that I had another assets field with a simpler "Restrict uploads to a single folder?" setting: {author.username|lower}
that was creating the field, and not the field I was testing with the setting above! Doh...
I supposed the real question is, therefore, how can I get a dynamic path, like the one above, to work?