Hot answers tagged

32

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 than a separate Single, you can set the slug of a Structure entry to __home__, which makes it act as the site's homepage and gives it that little Home icon in ...


24

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(3) %} This will give you the CategoryModel object for catSlug: {% set category = craft.categories.slug(catSlug).first() %} You can now access whatever you ...


16

This got it working for me: /section/{categoryFieldName.first.slug}/{slug}


14

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 loads the template spezified in the single's CP settings . Actually nothing you can't do manually with your home page's index.html: {# Replace the default `...


11

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 you could chop off “place-name” and find an index of all the places at /places/.


8

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

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 formatting is a bit off.


7

(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}


6

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). The term slug is just a convention of Craft. It doesn't matter what the names are, they can be anything useful to you: (?P<domain>[^/]+)/(?P<...


5

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: When this is done all URL requests made to "/artists/-whatever-" will be routed to the "artists/_entry" template. Now you can create your link like this: &...


5

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/ @rewrites; } location @enrewrites { rewrite ^/en/(.*)$ /en/index.php?p=$1 last; } location @nlrewrites { rewrite ^/nl/(.*)$ /nl/index.php?p=$1 last; }...


5

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. search will do some normalization routines on the value, and perform a very loose search for those keywords (see https://craftcms.com/docs/searching for more ...


4

Try enabling the config setting limitAutoSlugsToAscii, that should do what you want.


4

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 can't just set the Entry URL Format. If you really want to do this, you can do it using routes rather than the entry URL format. Uncheck the Entries in this ...


4

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 entries.


4

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 to load because they're just a index.html file in your templates/news/ folder (→ routing case 6 in https://craftcms.com/docs/routing). For a multi locale setup ...


4

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 can think of that may behave like you describe: Somehow, there is an existing record in your database that matches the URI of your Entry using the cics-west-...


4

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 because that calls .find() implicitly when passed an ElementCriteriaModel, but that doesn't actually change what the practice variable references in the rest of ...


4

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()->createCommand() ->update( '{{%elements_sites}}', ['slug' => ElementHelper::createSlug('new-slug')], [ 'elementId' =&...


4

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 be a problem, provided the Entry URI Format has been setup correctly for your Sections. It should take into account the slug of parent entries in generating ...


3

If you're talking about querying using SQL directly, then the craft_elements_i18n table is where all of the slugs are kept.


3

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: {{ member.firstNameField }} {{ member.title }} when outputting their names. Once you have done that, in your entry type settings you can set the entry title ...


3

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 is the entry's second save (one version exists) overwrite the slug with an empty string (will generate a new slug from the title). You should add another ...


3

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 replace in the string. Paraphrased from the source code of the globally available t() function: source: Defines which message source application component to use. ...


3

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 you.


3

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 with which you should be building sites. I wrote about this at length recently: https://cld.agency/blog/content-utopia To more directly answer the question: ...


3

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 entry: if no entry: 404 (this should never happen) if entry is everyPage.homePage: 404 if entry is the Craft home page single: set entry to everyPage.homePage ...


3

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 not To that end the following should work for your example: {% for entry in craft.entries.section('news').slug('not ' ~ craft.request.getSegment(2)).limit(6) ...


3

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, Asset, etc.), cross reference the elementId column of the result with the id column in the craft_elements table.


3

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 natural breadcrumbs for the hierarchy of content it’s likely going to be better from an SEO perspective Relevant feature request: https://github.com/craftcms/...


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