Hot answers tagged

32 votes

Add home page to a structure?

This isn't documented, so it's subject to change: When you set a Single to be the homepage, its slug is automatically set to __home__. If you want your homepage to be part of a Structure, rather ...
user avatar
  • 3,400
24 votes
Accepted

Get category title by slug

You need to add .first() when setting the category. As far as I can tell, if you don't have .first() only {{ category.slug }} will work. First get the slug: {% set catSlug = craft.request.getSegment(...
user avatar
  • 2,985
16 votes
Accepted

How would I include the first category slug in the section's entry URL format?

This got it working for me: /section/{categoryFieldName.first.slug}/{slug}
user avatar
  • 1,661
14 votes
Accepted

Add home page to a structure?

The "this is for the homepage" button available on single sections does two things for you, when you navigate to the home page's URL: it populates the entry variable with the single's entry model it ...
user avatar
  • 35.9k
11 votes
Accepted

Should I pluralize a channel's index slug?

It doesn’t matter to Craft, but generally I think it’s better to have consistent URLs, so they can be discoverable. For example if you land on /places/place-name, it would be reasonable to assume that ...
user avatar
8 votes
Accepted

How to add year and month to Entry URL Format

You're close! For the month part you need postDate|date("m") (this page has the php date formats). news/{postDate|date("Y")}/{postDate|date("m")}/{slug}
user avatar
7 votes
Accepted

Is it possible to use Craft as a webservice when no useragent is sent?

This post may help: Is it possible to disable `requireUserAgentAndIpForSession` for specific instances? Take a look at the requireUserAgentAndIpForSession config-setting. Post from phone, sorry if ...
user avatar
7 votes
Accepted

Error: URI already taken

(I'm writing this in case someone comes across the same problem) As @MatsMikkelRummelhoff pointed out, I still had to change the URL's format settings to team/{slug}
user avatar
6 votes
Accepted

How do I create an advanced route with multiple slugs?

Brad nails the problem in his comment: The error is because you've got two named subpatterns with the same name (<slug>) And the solution is simple... Change the name(s) of your subpattern(s)...
user avatar
  • 23.6k
5 votes
Accepted

Is it possible to add an entry value to the entry URL Format?

For this a good approach is to use the excellent Dynamic Routing system in Craft. Solution #1 First create your section "Artists": After that go to "Settings" -> "Routes" and add this Dynamic Route:...
user avatar
  • 2,824
5 votes
Accepted

Nginx Vhost Config - Get page based on translated URI and without parameters in url

Ok, I got it working with: nginx vhost config: location /en/ { try_files $uri $uri/ @enrewrites; } location /nl/ { try_files $uri $uri/ @nlrewrites; } location / { try_files $uri $uri/ ...
user avatar
  • 301
5 votes
Accepted

.relatedTo() not returning tags with spaces

In your working example, you’re mapping request.tags to the search param, but in the non-working example, you’re mapping it to the slug param. Those two params are handled in very different ways. ...
user avatar
4 votes
Accepted

How to transform German umlauts when creating slugs?

Try enabling the config setting limitAutoSlugsToAscii, that should do what you want.
user avatar
  • 7,248
4 votes

How would I include the first category slug in the section's entry URL format?

As I understand it, you want the url for an entry to be /section/category-slug/entry-slug. This is a little tricky, because if the entry has no category defined, it won't have a url, which is why you ...
user avatar
4 votes
Accepted

How to Generate Unique Slugs for a Section without ticking "Entries in this section have their own URLs"

You should probably just set your event dates using custom Date/Time fields rather than the Post Date and Expiration Date fields. That way you don’t have to fight with Craft’s restrictions on non-live ...
user avatar
4 votes
Accepted

Multilingual slug setup

The problem you're probably facing isn't that URLs like http://example.com/en/news/example http://example.com/fr/nouvelles/exemple don't work, but that you're not getting the sections' index pages ...
user avatar
  • 35.9k
4 votes
Accepted

Entry slug auto appends -1 even when the original slug is unique

I don't know the specific rules Craft uses but I believe Craft auto appends the -1 when it tries to save an Element that has a matching URI in the craft_elements_i18n table. A few scenarios that I ...
user avatar
  • 13.3k
4 votes
Accepted

Getting only slug in otherwise null object on routed template

You will need to use {% set practice = craft.entries.slug(slug).first() %} to fetch the real EntryModel, and not just an ElementCriteriaModel. I think the relatedTo criteria still works without it ...
user avatar
  • 4,361
4 votes

How to change an entry's slug on EVENT_AFTER_SAVE_ELEMENT?

You can change the value in the DB directly instead of using the Elements service $entry = $event->element; $elementId = $entry->id; $siteId = $entry->siteId; Craft::$app->getDb()->...
user avatar
4 votes
Accepted

Use of duplicate slugs, without -1

Craft doesn't care what the individual slug of an entry is on its own, it looks at the whole path to see if there are duplicates. Therefore having shop.com/candy and shop.com/about-us/candy shouldn't ...
user avatar
  • 3,604
3 votes

Querying database for slug match?

If you're talking about querying using SQL directly, then the craft_elements_i18n table is where all of the slugs are kept.
user avatar
  • 66.5k
3 votes
Accepted

customised slugs using custom field

Firstly I'd recommend splitting the first name and last name into seperate fields. That way in your templates it would look nicer: {{ member.firstNameField }} {{ member.lastNameField }} than having: ...
user avatar
  • 3,604
3 votes

Auto generation of localised slug

Yes, it's possible with a plugin. Make it listen to onBeforeSaveEntry events and look up how often the entry was already saved by counting entry versions using the getVersionsByEntryId method. If it ...
user avatar
  • 35.9k
3 votes
Accepted

Can I use translated properties for URL formats

This turned out to be easier than expected. It's not documented in the filters section of the docs, but the t() filter can take other parameters after the tokenised variables you might want to ...
user avatar
3 votes

Trouble with transliteration in slug caused by hardcoded charmap in craft.js

You can try using my plugin, which will overwrite the character map in craft.js by applying the customAsciiCharMappings setting: https://github.com/farmstudio/slugcharmap Tell me if it's working for ...
user avatar
  • 111
3 votes

Add home page to a structure?

From an IA and content-modelling perspective, putting all your site's "pages" in a Structure is fraught with problems, and, in my opinion, does a terrible disservice to the future-friendly approach ...
user avatar
  • 3,959
3 votes

Add home page to a structure?

I kludged this to work by creating a global whose value was the entry I wanted to use as the home page (everyPage.homePage), and then on _pages/_entry.html using twig to sort things out based on the ...
user avatar
3 votes
Accepted

How to filter entries by slug in url segment?

I think there is just some confusion between what should be a string or not. From the docs on Parameter Value Syntax: To exclude entries with a given value, you must pass in a string, prefixed with ...
user avatar
  • 2,301
3 votes
Accepted

Can't rename slug

You can connect to your database and run: SELECT * FROM craft_elements_i18n WHERE slug = 'forms'; to see what other element is already using the slug forms. To see what type of element it is (Entry,...
user avatar
  • 66.5k
3 votes

Multiple URL Formats per element type (Entries, Categories)

So semantically, I don’t love the URL format you’re coming up with. I’d like to see something like /gear/{category}/{entry} This gives you a few benefits it’s semantically readable… it gives you ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible