1

The entry variable stores values such as S001-LU, S009-SH, etc. I use this variable as default upload folder for assets. I would like to lowercase the value from the field, i.e. s001-lu, s009-sh, etc. How can I do this?

This doesn't work: enter image description here

1 Answer 1

2

Assuming that spaceId is a dropdown field(??) I believe you'll want this:

{spaceId.value|lower}

If you dump out a dropdown field in a template you'll notice that it doesn't give you a simple value, but is a big complicated object that represents the field and its chosen value. Craft does some magic in the background if you attempt to output the field without specifying .value, in the same way it'll output entry/category titles if you output just its parent object. However if you want to use filters on the value you'll need to be more explicit about what you're outputting.

If your spaceId field is not a dropdown but a relationship field (e.g., category select/entries select), then you'd need to fetch the related element first e.g.:

{spaceId.one().title|lower}

Bear in mind that subsequent changes to the space ID field won't dynamically move the uploaded assets to a new folder, so it might end up with very unpredictable results. Likewise if an editor decides to complete the upload field before selecting a space, I have no idea what'll happen then!

3
  • Hi James, Actually it is just a plain text field. I tried all your suggestions plus variations but I couldn't get it work. Error: **The Photos field's Default Upload Location setting has an invalid subpath." What tag do I have to use for plain text fields? The information on this page are relevant but not offering a solution: craftquest.io/articles/twig-craft-cms-control-panel
    – flip
    Apr 11 at 10:40
  • Hm, ok... I've tested now with a plain text field using the same syntax as in your post, and it works ok for me! Apr 11 at 15:09
  • I can confirm that for the text field my variable is working: {spaceId|lower}. I don't understand why it initially didn't work. Maybe something had been cached ...
    – flip
    Apr 15 at 17:41

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.