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 ...
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
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
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
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);...
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 ...
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 ...
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 ...
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, ...
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
...
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 ...
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.
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....
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 ...
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)
/...
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 ...
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,
...
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:
{% ...
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 ...
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....
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 ...
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 ...
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 ...
2
votes
DOM hash url in entry slug
This is impossible (not only in Craft, but in general) because the fragment (hash, the part after the #) is only used on the client-side. This is by design, it's part of the spec that the fragment is ...
1
vote
How to make a multiple route?
Have you tried processing the entire slug directly in your template, without setting a complex route? Check for the presence of the string "-and-", split the slug accordingly, build a Category query.
1
vote
Accepted
How to change an entry's slug on EVENT_AFTER_SAVE_ELEMENT?
I finally use this simple solution, which works pretty fine:
Event::on(
Element::class,
Element::EVENT_BEFORE_SAVE,
function(craft\events\ModelEvent $event) {
$entry = $event->...
1
vote
Accepted
How to point a static url to a file
You could create a simple plugin with Pluginfactory and copy the two function I'll give you to create the URL you like
Go to the page, turn on the light switch for "Controller" but leave the name ...
1
vote
How to point a static url to a file
You could setup a template at /menu that grabs the PDF you want and redirects with a 302 (not a 301 since it isn't permanent).
The URL would change, but that might be ok if you only care about having ...
1
vote
Accepted
Limit slugs to ASCII for auto-generated titles
Since the slug is used to generate assets folders, accents aren't suitable and results in question marks in the folder names.
You could do something similar to How to rename filename of asset before (...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
slug × 80url × 15
entry-slug × 14
craft3 × 9
entries × 8
localization × 5
entry × 5
routes × 5
routing × 5
categories × 4
structure × 4
sections × 4
plugin-development × 3
templating × 3
assets × 3
search × 3
saveentry × 3
getsegment × 3
craft4 × 3
plugin-craftcommerce × 2
matrix × 2
plugins × 2
php × 2
events × 2
tags × 2