Hot answers tagged

4

I pondered this for a while, and then did this, which will direct us to specific entries (not templates, I don't want to create more of those): {# We need a unique 404 for each site - just take us to the right slug relative to current URL #} {% switch currentSite.id %} {# siteA.com #} {% case 1 %} {% redirect '/my-404-slug' %} {# siteB.com #} {% ...


2

Not sure why Davids solution doesn't work for me, I'm using the following (Craft 3.2.8): return [ '<url:(?!api\b)\b\w+>' => ['template' => 'index'], ];


2

I did something similar for a site that showcased projects. In the top of my entry page, I had code like this: {% set entrySlug = craft.app.request.getSegment(2) %} {% set entry = craft.entries.section('services').slug(entrySlug).one() %} {% if entry is not defined or entry is null %} {% exit 404 %} {% endit %} And then I've got two routes: services/...


2

When a route is accessed, entry isn't automatically defined. The actual value for * is available in the any variable in your template—see this example: Route: projects/type/(*) Template: _test {# templates/_test.twig #} Substituted route param: {{ any }} Do note that entry is not automatically set by Craft for any custom routes! It's your responsibility ...


1

Update I was able to solve half of my Problem: Seems the Regex didn't like the "pure" slashes / in the URL between the parameters, once I escaped those, through backslashes like this: \/ it no longer gave me a yii\base\InvalidRouteException. The new Problem I have now is that it can't find the action I'm referring to, see below: // Path of File: ./src/...


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