1

How can I create dynamic paths for asset uploads? Basically I want my structure to be like so;

company-name-slug
  company
    logo-1.jpg
    image-2.jpg
  products
    product-image-1.jpg
  services
    service-image-1.jpeg
    service-image-2.jpeg

I have a field called gallery for the above assets.

Then I have sections for company, products and services. Each section uses the gallery field. Products and Services uses a related content field for the company (called company).

I want to use the gallery field across all sections, but then set the dynamic paths per service/product and company inline with the above structure.

Here is what I have tried but it just errors out. I have tried various combinations and some work some don't, but I cannot get to desired structure.

{% section == 'Company' ? slug : company.one|kebab %}/{section|kebab}

How can I achieve this or is there a way I can inject some better twig logic into the subfolder field?

enter image description here

1 Answer 1

1

So this was a simple fix and not to use {% %} tags but instead to use {{ }} tags. Changing the above logic in the subdirectories filed like so seems to have resolved the issue.

{{ section == 'Company' ? slug : company.one|kebab }}/{section|kebab}

Your Answer

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

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