Skip to main content
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}
Mosh's user avatar
  • 153
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 ...
Mike Pepper's user avatar
  • 4,391
4 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 ...
James Smith's user avatar
  • 5,344
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 ...
Ben Parizek's user avatar
  • 13.5k
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()->...
Robin Schambach's 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 ...
Jamie Wade's user avatar
  • 3,644
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 ...
andrew.welch's user avatar
  • 11.6k
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);...
Brad Bell's user avatar
  • 67.5k
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,...
Brad Bell's user avatar
  • 67.5k
3 votes

Export related entries by slug - not id

Short hacky answer Is this a one-time-operation? In this case, preparing the exported data manually is gonna be much simpler and quicker than any programmatic solution. Simply export both the entries ...
MoritzLost's user avatar
  • 11.5k
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 ...
carlcs's user avatar
  • 36.3k
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' ...
Douglas McDonald's user avatar
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 ...
Tom De Smet's user avatar
  • 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 ...
Mats Mikkel Rummelhoff's user avatar
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 ...
carlcs's user avatar
  • 36.3k
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, ...
Brad Bell's user avatar
  • 67.5k
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 ...
Mr. Sam's user avatar
  • 287
2 votes
Accepted

Dynamic Subfolder Paths - folder does not exist even after updating asset directories in settings

Ok, so I have figured out why this wasn't working. When clicking on reset asset indexes It was always popping up an alert saying that another asset was missing. I already knew this, and it was ...
ToddPadwick's user avatar
2 votes
Accepted

Advanced routing

I'd probably setup the following routes: 'blog/*/*' => 'blog/entry', 'blog/*' => 'blog/entry', And then on the entry template I'd get the last segment and split it to get the ID like so: {% ...
Clive Portman's user avatar
2 votes
Accepted

Channel entry: Slug from field pattern?

Ah I found it: the option to enter the custom slug is displayed when you uncheck the Title. And I set // don't accept umlauts for slugs 'limitAutoSlugsToAscii' => true, in the config.
Urs's user avatar
  • 639
2 votes
Accepted

Matrix Field Slug Output

That is returning an ElementQuery. I'm assuming you only need to get the first category. You need to use .one to get the category element. {% for row in entry.matrixField.all() %} {{ row....
Simon Kuran's user avatar
  • 3,015
2 votes
Accepted

call matrix entries

In order to get all elements from an ElementCriteriaModel you need to call the find() function {% set form = craft.entries({section: 'registration'}).find() %} You can them access those with normal ...
Robin Schambach's user avatar
2 votes
Accepted

Same content on different slugs

Because your Entry URI is setup as my-channel/{slug} , When you go to my-channel/post-slug-1 Craft automatically sets the variable 'entry' to the entry post-slug-1. You don't need to loop through the ...
Chattervast's user avatar
2 votes
Accepted

How to set index page as parent of a structure

If I understand your question, you want to combine a Single and a Structure into the same family of URL's, something like this: /services - (Single) /services/service-01 - (Structure Entry) /...
Jamie Wade's user avatar
  • 3,644
2 votes

How to change an entry's slug on EVENT_AFTER_SAVE_ELEMENT?

Another shorter and probably slightly more performant solution, using EVENT_BEFORE_SAVE: /* * Automatically update Element slugs to match the title if updated. */ Event::on( Element::class, ...
Udo's user avatar
  • 607
2 votes

How to remove something from the slug/url

In Craft 3 under your section config change the URL config https://docs.craftcms.com/v3/sections-and-entries.html#sections SEE: Entry URI Formats You can select what template it should render and ...
Dean Sanderson's user avatar
2 votes

How to remove something from the slug/url

I'd always defer to a Brad Bell answer, but if for some reason you needed to maintain the URI format and wanted to still customize a route you could use the Routes section of settings. https://docs....
Jessie Gilligan's user avatar
2 votes
Accepted

Allowing duplicate slugs in category paths

Jamie's answer is correct. If you set your Settings → Categories → Category URI Format to {parent.uri}/{slug} you will then be able have multiple time the same slug. Craft will take the parent into ...
Oli's user avatar
  • 7,495
2 votes
Accepted

nested sections

I think you might be referring to what Craft term an "Entry Type". A section can have a number of entry types, each of which can have their own set of fields and template. So you have a ...
Wallace's user avatar
  • 611
2 votes
Accepted

Special Characters in Slugs

Basically not possible with Craft, currently. Slugs go through a normalizeSlug() helper that removes what it thinks is HTML and inner-word punctuation. What I suspect is tripping you up is when it ...
Brad Bell's user avatar
  • 67.5k

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