4

I need to set an asset field's dynamic subfolder path to the User ID.

The field is within a matrix.

The matrix a field in a User profile.

Setting it to {currentUser.id}, {owner.author.id}, {object.author.id} results in an invalid path message when trying to upload to the asset field.

Adam Menczykowski
  • 1,390
  • 11
  • 22
  • I would like to use {currentUser.uid} ideally, so the upload location is anonymous to anyone peeking at the asset URL, however it seems uid isn't available on the User model. – Adam Menczykowski Jul 23 '18 at 16:37

1 Answers1

3

You should be using {{currentUser.id}} instead of {currentUser.id}

The difference is that double curly brace syntax works on the global scope, while single curly brace syntax tries to resolve itself on the current element. Relevant documentation.

Andris Sevcenko
  • 2,997
  • 11
  • 27
  • Fantastic! I did not know the rule about single {'s current element scope vs {{'s global scope. FYI I have used {{ currentUser.uid }} which creates a nice complex subdirectory something like: /images/a4b4f254-1beb-4110-be97-ab1c7d47f2a0/image.jpg Thank you for your answer. – Adam Menczykowski Jul 24 '18 at 06:26
  • I want to import assets and save them into their user folders. nothing of the above works... if I use {{currentUser.username}} it'll import the assets to whoever is logged in. {{user.username}} {user.username} does not work {{author.username}} {author.username} does not work as well. isn't there something more specific that will always save it into the users directory. Also if an admin would edit a user it would put it into the wrong directory... I guess I need some help... – outline4 Nov 09 '18 at 18:48
  • After investigating a little more I found out that you can use {id} or {username} if the asset field is attached to a user. it's much safer than using {{ currentUser.id }}. – outline4 Nov 10 '18 at 11:42