2

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?

2
  • What happens if you change the filename instead of the title? Maybe asset.slug == filename?
    – carlcs
    Aug 5 '14 at 12:10
  • It's definitely coming from the title as the filenames are totally different. Aug 5 '14 at 12:48
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 somehow?

4
  • 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! Aug 5 '14 at 15:54
  • 2
    @AndyHarris You could use the onSaveAsset event, and do the auto-completion yourself.
    – Victor In
    Aug 5 '14 at 23:02
  • 1
    @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. Aug 6 '14 at 9:23
  • 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! Aug 6 '14 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.