Answers.Body: <p>To include the handle of the slug, and the path within the structure based on the entry uploaded from in the upload location field I've found the following to work:</p>
  
  <p><code>{section.handle}/{parent.uri}/{slug}</code></p>
  
  <p>If there are any gotchas on this let me know and I'll edit this answer to include them.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-01T15:08:19.507Z
Answers.Text: Looks like we both came to the same conclusion at the same time. Looks like that should work!
Answers.UserDisplayName: Cavell Blood
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-01T15:05:55.370Z
Answers.LastActivityDate: 2017-05-01T15:05:55.370Z
Answers.UserDisplayName: Bonk
Answers.Body: <p>Assuming your Structure section is named Products with a handle of <code>products</code> you could try this:</p>
  
  <p><code>{section.handle}/{parent.uri}/{slug}
  </code></p>
  
  <p>Or you would have to restructure your entries to have a parent entry of Products.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-01T15:07:19.687Z
Answers.LastActivityDate: 2017-05-01T15:07:19.687Z
Answers.UserDisplayName: Cavell Blood
Body: <p>I'm working on a site with a structure containing products that are nested within "category"(not actually using craft's categories, just an entry type) pages. On each category or sub-category page I display each product within as a card with an image and title. The image is selected/uploaded from an asset field on the entry.</p>
  
  <p>In the interest of making the image folders as clean as possible I'm trying to set the asset upload locations based on the path of the entry it is uploaded from.</p>
  
  <p>For example: I have a product at the following location: <code>mysite.dev/products/doors/wood</code>. When I upload the image to be used in the product list view I'd like the path to be <code>mysite.dev/assets/img/products/doors/wood/imagefilename.jpg</code>.</p>
  
  <p>My default image upload location is set to <code>mysite.dev/assets/img/</code>.</p>
  
  <p>Is there a simple method I have missed in the documentation to pull the path of the entry as the asset field upload location? </p>
  
  <p>Or is it necessary to make a loop to go through the parent entries' slugs one by one, and if so what is my point of reference when creating the loop? Am I acting on the asset or the entry when I use a variable like <code>{slug}</code>? </p>
  
  <p>I'm tinkering with it and testing, but it is tedious since I must upload the image each time I try something new, and I feel like I might have missed something in the documentation.</p>
  
  <p>Edit:</p>
  
  <p>After a bit more tinkering I was able to get something that almost works. By setting upload location with the Images location in the dropdown and then <code>{parent.uri}/{slug}</code> I get something like <code>mysite.dev/assets/img/doors/wood/imagefilename.jpg</code>. This is missing the structure slug <code>products</code> at the beginning. </p>
  
Tags: <assets><variable><assetfilemodel>
Title: What is the proper way to set an asset's upload location using the slugs/ structure path of the entry it is selected from?
ThreadText: # What is the proper way to set an asset's upload location using the slugs/ structure path of the entry it is selected from?
  
  (Asked by: username_0 on 2017-05-01)
  
  I'm working on a site with a structure containing products that are nested within "category"(not actually using craft's categories, just an entry type) pages. On each category or sub-category page I display each product within as a card with an image and title. The image is selected/uploaded from an asset field on the entry.
  
  In the interest of making the image folders as clean as possible I'm trying to set the asset upload locations based on the path of the entry it is uploaded from.
  
  For example: I have a product at the following location: `mysite.dev/products/doors/wood`. When I upload the image to be used in the product list view I'd like the path to be `mysite.dev/assets/img/products/doors/wood/imagefilename.jpg`.
  
  My default image upload location is set to `mysite.dev/assets/img/`.
  
  Is there a simple method I have missed in the documentation to pull the path of the entry as the asset field upload location?
  
  Or is it necessary to make a loop to go through the parent entries' slugs one by one, and if so what is my point of reference when creating the loop? Am I acting on the asset or the entry when I use a variable like `{slug}`?
  
  I'm tinkering with it and testing, but it is tedious since I must upload the image each time I try something new, and I feel like I might have missed something in the documentation.
  
  Edit:
  
  After a bit more tinkering I was able to get something that almost works. By setting upload location with the Images location in the dropdown and then `{parent.uri}/{slug}` I get something like `mysite.dev/assets/img/doors/wood/imagefilename.jpg`. This is missing the structure slug `products` at the beginning.
  
  **Tags:** assets, variable, assetfilemodel
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-05-01. Score: 3 | Accepted answer
  
  To include the handle of the slug, and the path within the structure based on the entry uploaded from in the upload location field I've found the following to work:
  
  `{section.handle}/{parent.uri}/{slug}`
  
  If there are any gotchas on this let me know and I'll edit this answer to include them.
  
  > **Comments:**
  > **username_1**: Looks like we both came to the same conclusion at the same time. Looks like that should work!  
  
  ---
  
  ### Answer by username_1 on 2017-05-01. Score: 2
  
  Assuming your Structure section is named Products with a handle of `products` you could try this:
  
  `{section.handle}/{parent.uri}/{slug}`
  
  Or you would have to restructure your entries to have a parent entry of Products.
  
  
  ---
  
  