<p>Whenever you're not using the shortcut syntax with single braces you need to acces the element via <code>object</code>.</p>

<p>So add that var before <code>owner</code> etc. and you should be good.</p>

<p>One thing I noticed is that you can't use ternary syntax for conditionals within short syntax either but with Twig code you can:</p>

<pre><code>{{ object.owner.author ? object.owner.author.friendlyName }}
</code></pre>

CC BY-SA 3.0
2015-03-26T17:43:47.727Z
That's helpful, thanks. I've since realised that I don't need to re-use this field anyway. It was all a journey of discovery!
lowe_22
CC BY-SA 3.0
2015-03-24T00:51:54.073Z
2015-03-24T01:06:49.647Z
2015-03-24T01:06:49.647Z
carlcs
<p>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. </p>

<p>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:</p>

<p><code>{% if owner is defined %}{owner.author.username}{% elseif author is defined %}{author.username}{% endif %}</code></p>

<p>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 <em>inside</em> 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.</p>

<p>Perhaps I'm looking in the wrong place.</p>

<p>Does anyone have any experience trying to achieve what I'm attempting?</p>

<p>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...</p>

<p><strong>EDIT</strong></p>

<p>Since posting this, I have discovered that I had another assets field with a simpler "Restrict uploads to a single folder?" setting: <code>{author.username|lower}</code> that was creating the field, and not the field I was testing with the setting above! Doh...</p>

<p>I supposed the real question is, therefore, how can I get a dynamic path, like the one above, to work?</p>

CC BY-SA 3.0
2015-03-24T00:57:46.730Z
You can't reuse a configured (asset) field in matrix.
carlcs
CC BY-SA 3.0
2016-02-11T16:39:08.730Z
I found this useful if anyone else needs: https://craftcms.com/docs/assets-fields#dynamic-subfolder-paths
Sebastian Thomas
<assets><users>
Trouble with "restricted" upload folders
# Trouble with "restricted" upload folders

(Asked by: username_0 on 2015-03-23)

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?

**Tags:** assets, users
> **Comments:**
> **username_1**: You can't reuse a configured (asset) field in matrix.  
> **username_2**: I found this useful if anyone else needs: https://craftcms.com/docs/assets-fields#dynamic-subfolder-paths  

---

## 1 answers

### Answer by username_1 on 2015-03-24. Score: 3 | Accepted answer

Whenever you're not using the shortcut syntax with single braces you need to acces the element via object.
So add that var before owner etc. and you should be good.
One thing I noticed is that you can't use ternary syntax for conditionals within short syntax either but with Twig code you can:
{{ object.owner.author ? object.owner.author.friendlyName }}

> **Comments:**
> **username_0**: That's helpful, thanks. I've since realised that I don't need to re-use this field anyway. It was all a journey of discovery!  

---

