<p>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.</p>

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

<p>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.</p>

<p>Correct me if I am wrong but that is my understanding of it all.</p>

CC BY-SA 3.0
2014-10-24T00:34:26.257Z
Sorry my description was not very accurate...
Andrew Wisener
CC BY-SA 3.0
2014-10-24T03:22:59.803Z
note - I've updated my original post any thoughts welcome
Andrew Wisener
CC BY-SA 3.0
2014-10-21T08:33:07.303Z
2014-10-21T08:33:07.303Z
Jamie Wade
<p>I have setup a page that has image asset pickers on it and image asset pickers in a matrix field.</p>

<p>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.</p>

<p>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 :)</p>

<p>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.</p>

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

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

<p>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. </p>

<p>So I save my page and come back in...</p>

<p>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</p>

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

<p>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!</p>

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

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

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

<p>I wonder if predefined transforms are better?</p>

<assets>
slugs in asset picker not working until page is published
# slugs in asset picker not working until page is published

(Asked by: username_0 on 2014-10-21)

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?

**Tags:** assets

---

## 1 answers

### Answer by username_1 on 2014-10-21. Score: 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.

> **Comments:**
> **username_0**: Sorry my description was not very accurate...  
> **username_0**: note - I've updated my original post any thoughts welcome  

---

