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.