7 votes
Accepted

How to load a different template for parent page

First, I'd recommend that you have a total of 3 templates: _child.html for your child entries, _parent.html for your parent entries, and finally _entry.html which will basically work as a "controller" ...
Mats Mikkel Rummelhoff's user avatar
7 votes
Accepted

Routing within a single page app integration

To pull this off, first you’ll have to make sure all of your Element API endpoints begin with something consistent, like api/ or data/, etc. Then create a route in craft/config/routes.php that will ...
Brandon Kelly's user avatar
7 votes
Accepted

Asset (image) public URL does not work

The issue is that your Asset Volume URL is @web/image but your Asset Volume path is @webroot/assets/art That means that Craft will look for the images on disk (to do transforms, etc.) in web/assets/...
andrew.welch's user avatar
  • 11.6k
6 votes

Routing within a single page app integration

In case someone uses Craft 3, this should work: <? return array( '<url:(?!api\/).*>' => ['template' => 'index'] );
David B.'s user avatar
6 votes
Accepted

Entry URL Format

There are two ways you can set that up, depending on whether you want Brand entries to have a similar URI format (just without the 3rd segment), e.g. category/brand. Assuming you do, edit your Brands ...
Brandon Kelly's user avatar
5 votes
Accepted

How to setup custom site routes created by user in plugin settings

You can use the registerSiteRoutes() hook in your plugin's primary class. Assuming your custom URL formats are stored in an array in a plugin setting called customRoutes (use AttributeType::Mixed for ...
Mats Mikkel Rummelhoff's user avatar
5 votes
Accepted

How to do advanced routing to a Craft channel

I'm not sure I understand your question, but to try: There actually isn't a "standard Craft routing", for channel Sections or anything else. In your channel's Section settings (available via ...
Mats Mikkel Rummelhoff's user avatar
5 votes
Accepted

Installing other PHP app in sub directory

Yes, possible. You just need to override the URL routing within the subdirectory, so requests to /sub/* get routed to /sub/index.php rather than /index.php. For example, if you’re using Apache, just ...
Brandon Kelly's user avatar
5 votes

"Template not found" error when attempting to access static web page

The problem was specific to my local set up. The dockerfile for this project did not mount the entire /web/ folder, so the live application was ignoring local changes I made to it. Solution: Change ...
vlasits's user avatar
  • 203
4 votes
Accepted

How to troubleshoot routes

Remove the / at the end of databases/ and it should work. Technically, index.html is not required either, so you could just use library-database-demo-section.
Brad Bell's user avatar
  • 67.5k
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
Accepted

How to route 404 errors for multi-site Craft?

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 ...
4midori's user avatar
  • 656
3 votes
Accepted

Redirecting "if entry is not defined" returns 404 instead

The reason you're getting a 404 is because Craft isn't even hitting your help/_entry.html template. Because there's no entry matching the URI /help/asdf, the template will never render and the request ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Craft Routing / Variables with Differing URI

Go to Settings → Routes, and create a route like this: Then create that partners/_partner_news_entry.html template. (You can change the location/name of the template if you want; just make sure it ...
Brandon Kelly's user avatar
3 votes
Accepted

How to redirect site root to preferred language in multi-language site?

I would put a .htaccess file in the public HTML folder and let Apache deal with it, that way you don't have the overhead of PHP/Craft having to deal with that request.
Brad Bell's user avatar
  • 67.5k
3 votes
Accepted

Displaying entires by year from a custom date field

Looks like I finally found an answer to it year being my param date being my custom date field {% set dateParam = 'and, >= ' ~ year ~ '-01-01, < ' ~ (year + 1) ~ '-01-01' %} <ul> {% ...
Eric Chantigny's user avatar
3 votes

CraftCMS with Cloudfront Full Page Delivery

That's the dream, isn't it? CDN everywhere, no database hits, etc. How "static" is your site? Unlike other CMS, the great thing about Craft is that you can store information everywhere and pull it out ...
RitterKnight's user avatar
  • 6,582
3 votes
Accepted

Secondary Template for Structure

It sounds like you need to create a dynamic route by going to Settings > Routes > "New Route". Then you'd set your custom route to profiles/{slug}/email-signature and decide which template to serve ...
Ryan's user avatar
  • 1,952
3 votes

How to route to a controller action in Craft3?

The problem ended up being something underlying in craft or yii2 that will not route the word "echo". I changed out "echo" to "test" and it works fine. Even with both routes in, one does not and one ...
Rick Kukiela's user avatar
3 votes
Accepted

Why is the parent slug showing up in the child slug in a structure?

Pretty sure that the ResaveElements task just hadn't run yet - my queue was stuck. Once I cleared the stuck items, the issue resolved on its own!
Katie Fritz's user avatar
3 votes
Accepted

Make segment in the middle of a route optional

Your regex is going to become more complex and potentially less specific if you try to address both scenarios in a single route as the height and width parameters match numbers and the final segment ...
Ben Parizek's user avatar
  • 13.4k
3 votes
Accepted

Variable "entrySlug" does not exist Routing

If I'm not mistaken, I don't think setting up the route via the CP does the fancy advanced rule stuff described here. You'll therefore want to do that via the config/routes.php file with something ...
Jalen Davenport's user avatar
  • 3,045
3 votes
Accepted

Routing: How can I ignore a parameter in route definition?

It sounds like you might be trying to blend Craft/Yii routing with Rewrites (if you're coming from an Apache background). I believe what Craft interprets this as is an attempt to map a request to ...
August Miller's user avatar
3 votes
Accepted

CORS preflight check failing for AJAX login form on different domain

Thanks for posting your headers, that was very helpful. I experienced a very similar problem just the other day and was able to work it out via trial and error and a whole bunch of Google/...
Dalton Rooney's user avatar
3 votes
Accepted

Dynamic URL generated by a custom field dropdown value

In the section settings, you can specify a dynamic entry URI format. As the docs say, this box is in fact a mini Twig template, and is preloaded with the element being saved (accessible as object) and ...
James Smith's user avatar
  • 5,189
3 votes
Accepted

Craft's case-insensitive routing

In most cases, case-sensitivity depends on the database collation. By default, Craft uses case insensitive collations (utf8_general_ci or utf8mb4_0900_ai_ci, depending on the charset). You can change ...
MoritzLost's user avatar
  • 11.3k
3 votes

Craft's case-insensitive routing

If you're worried about search engines indexing some page where someone is linking to with a different case, as mentioned by Moritz, that's what you use the canonical tag for: <link rel="...
RitterKnight's user avatar
  • 6,582
2 votes
Accepted

Get entry route

You can get an entry’s URI via $entry->uri. If you want to be able to tell if an entry’s URI is actually changing, you will also need to listen to the onBeforeSafeEntry event, and store its ...
Brandon Kelly's user avatar
2 votes

Set a dynamic `activateAccountSuccessPath`

Completely untested, but something like this should do it. Create a simple plugin and add this to the main plugin class: public function init() { craft()->on('users.onBeforeActivateUser', ...
Brad Bell's user avatar
  • 67.5k
2 votes

How to redirect site root to preferred language in multi-language site?

Here's the setup I used for the .htaccess file if anyone is interested: RewriteEngine on RewriteCond %{REQUEST_URI} ^/$ RewriteRule (.*) http://example.com/new_directory/ [R=301,L]
Justin K's user avatar
  • 309

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