Answers.Body: <p>I think for this you'd want to write a <a href="https://craftcms.com/docs/plugins/events-reference#entries-onSaveEntry" rel="nofollow noreferrer">custom plugin</a> that listened to the <a href="https://craftcms.com/docs/plugins/events-reference#entries-onSaveEntry" rel="nofollow noreferrer"><code>onSaveEntry</code></a> event.</p>
  
  <p>That plugin would check that the given entry is in the correct section/entry type you're interested in, pull any data from custom fields set on the entry update the slug for that entry accordingly.</p>
  
  <p>I'd probably look at updating the slug directly in the database and avoid going back through <code>craft()-&gt;entries-&gt;saveEntry()</code> to avoid getting into an infinite save entry loop.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-21T22:28:59.513Z
Answers.Text: Old answer, I know, but is this something I could do easily enough with a module? - trying my hand at learning how to do it.
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-15T22:56:16.517Z
Answers.LastActivityDate: 2017-06-15T22:56:16.517Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm not sure I've seen this exact question, but I'm curious how I can include custom and/or auto-generated parts of a slug. It's not the URI creation, but the slug itself.</p>
  
  <p>For Instance:</p>
  
  <p><code>{slug}-{id}</code> would turn into <code>lorem-ipsum-dolor-sit-amet-123456</code> on submit</p>
  
  <p>and from there on the variable <code>{{entry.url}}</code> would be <code>example.com/lorem-ipsum-dolor-sit-amet-123456</code>.</p>
  
  <p>I know ExpressionEngine had an option in the Channel preferences called URL Title Prefix, so this would go along those lines, but more auto-generated than a predefined set of words.</p>
  
  <p>If it changes things, this is specifically for Commerce and Digital Products at the moment.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-15T18:54:03.700Z
Comments.Text: You can do so with Craft's [Dynamic Entry Titles](https://craftcms.stackexchange.com/questions/20857/auto-generating-slug-with-custom-fields-or-id)
Comments.UserDisplayName: AbbeyDesign
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-15T19:25:27.213Z
Comments.Text: https://craftcms.com/docs/templating/filters#kebab
Comments.UserDisplayName: Brad
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-15T20:30:40.843Z
Comments.Text: I don't necessarily want the title to be dynamic. The title should be able to be populated by the user. But upon submit, or even right away when the create entry page loads, the slug should be prepended or appended by the ID.
  
  @Brad I don't know how that kebab filter helps?
Comments.UserDisplayName: John Johnson
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-16T12:56:33.407Z
Comments.Text: Dynamic Entry Titles are dynamic in the sense saving an entry would create a slug depending on any combination of fields you want. You can set your title field to be {entry.user-entered-slug}-{entry.id} or {entry.fieldA}-{entry.fieldB}-{entry.postDate}-some-text-{entry.id} etc etc.
Comments.UserDisplayName: AbbeyDesign
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-16T13:26:13.173Z
Comments.Text: OK, I think I'm following. I could create a psuedo title field and behind the scenes it's populating the actual title field with the pertinent info I need. I'll try this...
Comments.UserDisplayName: John Johnson
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-16T13:29:31.170Z
Comments.Text: Upon looking, it doesn't appear that Craft Digital Products has the ability to hide the title field, so this method is not possible in the context I need it.
Comments.UserDisplayName: John Johnson
Tags: <slug>
Title: Auto generating slug with custom fields or ID
ThreadText: # Auto generating slug with custom fields or ID
  
  (Asked by: username_0 on 2017-06-15)
  
  I'm not sure I've seen this exact question, but I'm curious how I can include custom and/or auto-generated parts of a slug. It's not the URI creation, but the slug itself.
  
  For Instance:
  
  `{slug}-{id}` would turn into `lorem-ipsum-dolor-sit-amet-123456` on submit
  
  and from there on the variable `{{entry.url}}` would be `example.com/lorem-ipsum-dolor-sit-amet-123456`.
  
  I know ExpressionEngine had an option in the Channel preferences called URL Title Prefix, so this would go along those lines, but more auto-generated than a predefined set of words.
  
  If it changes things, this is specifically for Commerce and Digital Products at the moment.
  
  **Tags:** slug
  
  > **Comments:**
  > **username_1**: You can do so with Craft's [Dynamic Entry Titles](https://craftcms.stackexchange.com/questions/20857/auto-generating-slug-with-custom-fields-or-id)  
  > **username_2**: https://craftcms.com/docs/templating/filters#kebab  
  > **username_0**: I don't necessarily want the title to be dynamic. The title should be able to be populated by the user. But upon submit, or even right away when the create entry page loads, the slug should be prepended or appended by the ID.  @username_2 I don't know how that kebab filter helps?  
  > **username_1**: Dynamic Entry Titles are dynamic in the sense saving an entry would create a slug depending on any combination of fields you want. You can set your title field to be {entry.user-entered-slug}-{entry.id} or {entry.fieldA}-{entry.fieldB}-{entry.postDate}-some-text-{entry.id} etc etc.  
  > **username_0**: OK, I think I'm following. I could create a psuedo title field and behind the scenes it's populating the actual title field with the pertinent info I need. I'll try this...  
  > **username_0**: Upon looking, it doesn't appear that Craft Digital Products has the ability to hide the title field, so this method is not possible in the context I need it.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2017-06-15. Score: 2
  
  I think for this you'd want to write a [custom plugin](https://craftcms.com/docs/plugins/events-reference#entries-onSaveEntry) that listened to the [`onSaveEntry`](https://craftcms.com/docs/plugins/events-reference#entries-onSaveEntry) event.
  
  That plugin would check that the given entry is in the correct section/entry type you're interested in, pull any data from custom fields set on the entry update the slug for that entry accordingly.
  
  I'd probably look at updating the slug directly in the database and avoid going back through `craft()->entries->saveEntry()` to avoid getting into an infinite save entry loop.
  
  > **Comments:**
  > **username_4**: Old answer, I know, but is this something I could do easily enough with a module? - trying my hand at learning how to do it.  
  
  ---
  
  