I am building a drupal 7 commerce site, I have installed inline entity form module and adding products from inside the products displays. Since I will have thousands of product displays and products, I thought of finding a way to automatically separate pictures into sub-folders at time of adding the product displays and products. So I have installed this module Filefield Paths I managed the image field in the product display and set the path setting to: pictures/products-displays/[node:field-taxonomy-terms:1:root] (as per below screenshot)

enter image description here

So it uploads the image, to a folder named as per the product parent category, under products displays folder. Which is exactly what I want. a nicely organized pictures structures.

The problem is not with product display images. It is with product images. I want to have the same things for products where I need images of products to be saved under

pictures/products/(parent category of the product display this product belongs to)

I understand that:

  • The product categories vocab is a reference field for Product Display and not product
  • A product can belong to more than one product display, so there there is no reference on the product data to the product display it belongs to, only the other way around.

So I thought my only workaround to get the category of the product display to which the product belongs to is to use the page url. (I edit my products from the same page of product display edits..remember I am using inline entity)

So [current-page:url:args:value:1] will give me the product display node id, when I am on the page of product display and its products editing. What I need is to get the parent category of that product display node id and use it for the path. in other words I need to have a token that will get me the parent category of the product display id on the page I know the below does not work... but just to give an idea about the logic

  • What is your purpose in doing this?
    – nvahalik
    Dec 7, 2015 at 11:59
  • Having thousands of files under one folder, causes serious performance issues, even failure to access the folder. Dec 7, 2015 at 15:10
  • This is normally only a problem if you have hundreds of thousands or millions of files in a directory. Otherwise, this is a bit of an over-optimization. If you're still concerned, consider just using date or product type token to split the product images up by taxonomy terms linked to product ideas won't really fly.
    – nvahalik
    Dec 7, 2015 at 15:33
  • if I may ask here ... since there aren't that many questions about Drupal Commerce and Image paths ... can you do something like: store/pics/[node:nid]/[commerce-product:product-id] I can't seem to get node nid, how come we don't have access via Filefield Paths to nid yet have access to the product-id? Sep 28, 2016 at 4:35

1 Answer 1


What you are proposing to do won't really work since you cannot embed tokens within tokens. You're going to need to split the images up based on something else. Here are some options:

  • Product type [commerce_product:type] (e.g. "shirt" - I haven't checked this one.)
  • Date [current-date:custom:Ym] (e.g. "201512")

Furthermore, unless you have hundreds of thousands of images, you're likely not going to see much of a performance degradation. If you do have that many images, perhaps you should consider using a CDN or some external system to offload image handling.

  • Thanks, I think I should have created different product types from the start. Anyway, I am using the custom date now. I read in many places that thousands of files are enough to create issues... Dec 8, 2015 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.