<p>Could you add your own field to use as a slug?</p>

<p>When you edit an Asset Source in Settings you get the <code>Field Layout</code> tab same as you do for Entries. You could maybe add something there and then combine this with a <a href="http://buildwithcraft.com/docs/routing#advanced-routing" rel="nofollow">Route</a> somehow?</p>

CC BY-SA 3.0
2014-08-05T15:54:25.937Z
That was my backup plan, but it doesn't do the initial auto completion of the field that the slug field does which I like!
Andy Harris
CC BY-SA 3.0
2014-08-05T23:02:24.403Z
@AndyHarris You could use the [`onSaveAsset`](http://buildwithcraft.com/docs/plugins/events-reference#assets-onSaveAsset) event, and do the auto-completion yourself.
Victor
CC BY-SA 3.0
2014-08-06T09:23:53.167Z
@AndyHarris - Further to Victor's suggestion, if you take a look in `craft/app/helpers/ElementHelper.php`, there is a static method called `createSlug` which does all the hard work for you.
Steve Holland
CC BY-SA 3.0
2014-08-06T10:12:59.090Z
OK thanks chaps, I'll check that out - however, the slug I'm getting back must be coming from somewhere so I'm still keen to know if we can access that!
Andy Harris
CC BY-SA 3.0
2014-08-05T15:10:50.887Z
2014-08-05T15:10:50.887Z
Steve Holland
<p>I'm trying to create a site with a gallery, and am investigating the possibility of getting Craft to treat an asset as an entry so I can display a detail page for an image without having to create an entry for it specifically.</p>

<p>I think it might do what I need, but I've fallen at the first hurdle whereby according to the documentation (unless I've missed it) assets don't have a slug. I could use ID, but the client will want keywords in the URL blah blah.</p>

<p>If I pull an asset and output {{ asset.slug }}, it does return what I'd want it to. The problem is, if I edit the title, that value isn't updated and there doesn't appear to be a way to get to it.</p>

<p>Is it possible to get to this somehow?</p>

CC BY-SA 3.0
2014-08-05T12:10:17.583Z
What happens if you change the filename instead of the title? Maybe `asset.slug` == filename?
carlcs
CC BY-SA 3.0
2014-08-05T12:48:28.943Z
It's definitely coming from the title as the filenames are totally different.
Andy Harris
<assets><assetfilemodel>
Is there a 'slug' for assets?
# Is there a 'slug' for assets?

(Asked by: username_0 on 2014-08-05)

I'm trying to create a site with a gallery, and am investigating the possibility of getting Craft to treat an asset as an entry so I can display a detail page for an image without having to create an entry for it specifically.

I think it might do what I need, but I've fallen at the first hurdle whereby according to the documentation (unless I've missed it) assets don't have a slug. I could use ID, but the client will want keywords in the URL blah blah.

If I pull an asset and output {{ asset.slug }}, it does return what I'd want it to. The problem is, if I edit the title, that value isn't updated and there doesn't appear to be a way to get to it.

Is it possible to get to this somehow?

**Tags:** assets, assetfilemodel

> **Comments:**
> **username_1**: What happens if you change the filename instead of the title? Maybe `asset.slug` == filename?  
> **username_0**: It's definitely coming from the title as the filenames are totally different.  

---

## 1 answers

### Answer by username_2 on 2014-08-05. Score: 4

Could you add your own field to use as a slug?

When you edit an Asset Source in Settings you get the `Field Layout` tab same as you do for Entries. You could maybe add something there and then combine this with a [Route](http://buildwithcraft.com/docs/routing#advanced-routing) somehow?

> **Comments:**
> **username_0**: That was my backup plan, but it doesn't do the initial auto completion of the field that the slug field does which I like!  
> **username_3**: @AndyHarris You could use the [`onSaveAsset`](http://buildwithcraft.com/docs/plugins/events-reference#assets-onSaveAsset) event, and do the auto-completion yourself.  
> **username_2**: @AndyHarris - Further to username_3's suggestion, if you take a look in `craft/app/helpers/ElementHelper.php`, there is a static method called `createSlug` which does all the hard work for you.  
> **username_0**: OK thanks chaps, I'll check that out - however, the slug I'm getting back must be coming from somewhere so I'm still keen to know if we can access that!  

---

