2

Is there any way to set a different url format for each entry type of a section?

I have an entry type "image" on which I will be using the Randomm plugin by Fred Carlsen to generate random strings for the URLs. Something like mysite.com/image/324739483. So I have to set the URL format to image/{customFieldHandle}.

But I also have an entry type "articles" and I'd like to add the actual article name in the URL, like mysite.com/articles/some-article-name.

3

You can set the URL format to something like this and it should work:

{% if object.type == "image" %}image/{customFieldHandle}{% elseif object.type == "articles" %}articles/{slug}{% endif %}
  • Nice! Would you mind marking it as the answer? – Brad Bell Sep 22 '14 at 1:42
  • duh, always forget that.. marked ;) – rey Sep 22 '14 at 3:04
2

You can't create a separate url format for each type, the url format is defined on a per section basis. But you can use the type as part of the url, if that helps. For instance, you can set the url format to {type.handle}/{slug}. On a recent project I had an article section with entry types like news, video, story, etc. The resulting url structure was /news/slug, /video/slug, /story/slug, etc.

Also, there is nothing stopping you from defining your url structure using routes, and creating the url's based on whatever variables, including entry type. But it would require some more work since you'd have to make sure all your links conform to your defined routes instead of the actual entry urls.

If you provide more info on what you're trying to achieve, maybe I can provide a more concrete solution.

  • Hi Andre, I just edited my question with more info, thanks! – rey Sep 20 '14 at 20:03

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.