1

I have setup a page that has image asset pickers on it and image asset pickers in a matrix field.

I have setup the fields to allow a single directory and a { slug } for the normal field pickers and { owner.slug } for the matrix field destinations.

So far so good, if I work with a saved page it all works beautifully, the images get saved in the folder with the name of the page :)

But it doesn't seem to work for a new page, when I pick an image the dialog that comes up does not show the { slug } folder and when upload and select an image it shows a broken image in live preview mode. Once I save the page and go back in it all comes good.

Ok my description was poor, I am certain this is a bug, here are the details...

  • I have an asset repository called property-images
  • I have a section template with 2 image fields mainImage, searchImage and another image inside a matrix field
  • mainImage and searchImage are set to use a single source (property-images) with the location set to {slug}
  • the matrix image is the same with the location set to {owner.slug}

I create a new page and save it (so the page is created and has a slug) I go back into the page and select mainImage, it works beautifully, and loads images into a sub folder correctly. If i create a new matrix block and select an image, I don't get the asset in my sub folder display but some sort of tmpassets folder. OK I kind if get this, because the block isn't created yet, I don't like it but I can live with it. Now when I look at live preview the image doesn't preview, the image url it renders doesn't exist.

So I save my page and come back in...

Now the image I picked in the block has been moved to the correct assets folder but still doesn't render anything, the transformed images aren't there

If I remove the image from the matrix block and re-pick it now it all works fine.

So it seems to explain to the content editor how to use this I need to tell them whenever they create a new matrix block they need to publish the page and come back in and then pick the image and then it's good. I can tell you that is not going to fly with this client!

I've also experimented with a page in draft but a different set of weird things results.

Oh one more thing! I'm using transforms in code, so something like:

{% set lrg = { mode: 'crop', width: 1400, height: 866, quality: 75, position: 'center-center' } %}
img src='{{ image.getUrl(lrg) }}'

I wonder if predefined transforms are better?

1 Answer 1

2

This is expected behaviour. By dynamically creating asset folders based off the entry slug, the entry itself has to first be saved. This is so when assets are uploaded, Craft can look at the slug of your entry, create an asset folder with the same name and put the assets there.

By uploading assets to an unsaved entry, the slug doesn't really exist yet, so Craft won't know where to put your files.

As you say, the only way round this is to save your entry first, so Craft knows what to name your folders, and then on the second save add in your assets.

Correct me if I am wrong but that is my understanding of it all.

2
  • Sorry my description was not very accurate... Commented Oct 24, 2014 at 0:34
  • note - I've updated my original post any thoughts welcome Commented Oct 24, 2014 at 3:22

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.