Answers.Body: <p>So this was a simple fix and not to use <code>{% %}</code> tags but instead to use <code>{{ }}</code> tags. Changing the above logic in the subdirectories filed like so seems to have resolved the issue.</p>
  
  <pre><code>{{ section == 'Company' ? slug : company.one|kebab }}/{section|kebab}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-23T13:33:34.867Z
Answers.LastActivityDate: 2020-04-23T13:33:34.867Z
Answers.UserDisplayName: Terry Upton
Body: <p>How can I create dynamic paths for asset uploads?
  Basically I want my structure to be like so;</p>
  
  <pre><code>company-name-slug
    company
      logo-1.jpg
      image-2.jpg
    products
      product-image-1.jpg
    services
      service-image-1.jpeg
      service-image-2.jpeg
  </code></pre>
  
  <p>I have a field called gallery for the above assets.</p>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>{% section == 'Company' ? slug : company.one|kebab %}/{section|kebab}
  </code></pre>
  
  <p>How can I achieve this or is there a way I can inject some better twig logic into the subfolder field?</p>
  
  <p><a href="https://i.sstatic.net/sHRXj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sHRXj.png" alt="enter image description here"></a></p>
  
Tags: <assets><assets-field><subfolder>
Title: Dynamic Asset Sub Folder Paths based on section and. if/else or turnery operators
ThreadText: # Dynamic Asset Sub Folder Paths based on section and. if/else or turnery operators
  
  (Asked by: username_0 on 2020-04-23)
  
  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](https://i.sstatic.net/sHRXj.png)](https://i.sstatic.net/sHRXj.png)
  
  **Tags:** assets, assets-field, subfolder
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-04-23. Score: 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}
  
  ```
  
  
  ---
  
  