Hot answers tagged

9 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}
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}
  • 153
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)...
  • 23.8k
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. ...
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 ...
  • 36k
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 ...
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 ...
  • 4,381
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 ...
  • 13.3k
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()->...
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 ...
  • 3,604
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,...
  • 67k
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 ...
  • 11.3k
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.
  • 67k
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: ...
  • 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 ...
  • 36k
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 ...
  • 4,564
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 ...
  • 111
3 votes
Accepted

Bulk regenerate slugs

Or will I have to write a temporary custom controller action that I can trigger to loop over all entries to redo their slug? This one. The plugin could then just use StringHelper::asciiString($slug);...
  • 67k
2 votes

How to create an auxiliary page with sub url?

First you'll want 3 templates — I'll call them 'news/index.html', 'news/_entry.html', and 'news/_extra.html'. (fyi... using an underscore before the template name is good practice as it prevents the ...
2 votes
Accepted

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

Yeah, this is an issue we're aware of of the 2.x branch that's been resolved for Craft 3.x and we probably won't back-port because of the complexity involved. But in 2.x, we naively assumed that ...
  • 67k
2 votes
Accepted

Twig: Show specific entry by url

You can get the parts of your URL using the getSegment() function. https://craftcms.com/docs/templating/craft.request#getSegment Then use the slug parameter and the criteria model’s first() method to ...
  • 36k
2 votes
Accepted

Custom URL based on Categories

I wouldn't normally set up a site like this — but given your setup, the following should work. In the category settings, make sure that your category has 'Entries in this section have their own URLs' ...
2 votes
Accepted

Include related entry slug in URl

Assuming your store/brand field handle in your new channel is relatedEntryField, set your URL format when you're defining the channel section to: {relatedEntryField.first().slug}-{slug} That'll pull ...
  • 6,562
2 votes
Accepted

Setting an entry slug from a pluign

If you set the slug directly on the entry element, it should work! public function init() { craft()->on('entries.saveEntry', function(Event $event) { $entry = $event->params['entry']...
2 votes

Category slug is getting numbers appended to it

When you save an entry/category that is supposed to have its own URL, Craft will assign it a unique URI, based on the section/category group’s URL Format setting. For example, let’s say you have a ...
2 votes

How to make a code/settings for accessing the one database from 2 different html files with {slug}

This makes more sense :) So basically, you want to have info from one entry on multiple pages and your problem is that in the section settings, you can only define 1 template for an entry. One way ...
  • 1,456
2 votes
Accepted

Can I use a structure without slugs?

You'll need to create a listing template for the base /projects URL, and make that template render for that URL. The easiest way is to just add a template called /templates/projects/index.html, in ...
2 votes

Can I give every structure entry a custom layout by using the same template?

You can setup a dynamic route for /handle/<slug>/followuppage and route the requests to your follow-up page template. From that template you’d have access to a variable called slug that you ...
  • 36k
2 votes

Receive all used slugs

I already found a solution. I just created a simple query: SELECT content.elementId entryId, title, uri FROM `craft_content` content JOIN craft_elements elements ON elements.id = content.elementId ...
  • 287
2 votes

Auto generating slug with custom fields or ID

I think for this you'd want to write a custom plugin that listened to the onSaveEntry event. That plugin would check that the given entry is in the correct section/entry type you're interested in, ...
  • 67k

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