Skip to main content

Questions tagged [routes]

Questions about how Craft handles a request.

Filter by
Sorted by
Tagged with
9 votes
2 answers
9k views

Does Craft CMS have an API?

Does Craft CMS have an API that third-party webapps can access? Maybe a REST API which you can log in to and send GET, PUT, POST, DELETE commands to, from a third-party app? It seems like it should ...
Magne's user avatar
  • 193
8 votes
1 answer
2k views

Route breaks Single Entry

I'm following the documentation to create a thank-you page when the user submits the form. I have a single created for /contact-us/ and I want the user to be redirected to /contact-us/thank-you/ when ...
Keiron Lowe's user avatar
8 votes
1 answer
1k views

How do I handle named route variables passed to a controller?

I'm writing a plugin that uses the registerSiteRoutes hook to create some new routes, and passes those routes to some controllers. In these routes, I have a few pieces of the URL that I'm capturing as ...
shanecavaliere's user avatar
7 votes
1 answer
1k views

Routing templates thats start with an underscore

More of a question than problem; I see this often - templates that start with an underscore. For example, _entry.html. Reading the Craft docs: Note that if any of the URI segments begin with an ...
Damon's user avatar
  • 4,706
7 votes
1 answer
1k views

Is it possible to tell Craft to ignore requests to under a certain path?

Unfortunately, I'm in a position where I need to run a Craft and WordPress installation out of the same directory. The WordPress install is under the sub-directory /blog. When I visit http://mysite....
cmal's user avatar
  • 815
6 votes
2 answers
1k views

Can we define routes (non-CP) in plugins?

I don't suspect it's currently possible but I would be pleasantly surprised to find that it is. I'm going to use an example from Django because I've seen it used there and a similar implementation ...
Tyler Willingham's user avatar
6 votes
1 answer
1k views

Craft CMS plugin route redirects to login when not logged into Craft

I created a simple Craft plugin to allow for custom action URLs. Specifically, I have a path "actions/api/sendEmail" that hits a method in my plugin's controller. It sends an email from a contact form ...
Luke Peters's user avatar
6 votes
2 answers
3k views

Is it possible to access Twig variables in a plugin variable using PHP?

I have a controller that returns route variables to the page: craft()->urlManager->setRouteVariables(array( 'errors' => $entry->getErrors() )); On the page that gets loaded, I can ...
Ben Parizek's user avatar
  • 13.5k
6 votes
1 answer
666 views

Is it possible to setRouteVariables when redirecting after a successful form submission?

I have a form. It submits. It saves. I'd like to pass the newly-created, complete form object back to the 'thank you' page template so that I can display the values that were submitted. I do not ...
Ben Parizek's user avatar
  • 13.5k
5 votes
2 answers
1k views

`routes.php` config example

I want to move some permanent routes from the admin to my routes config file so that they can be version controlled. in the admin... news-sort/month/<year>/<month> .... news-sort/tag/<...
mjr's user avatar
  • 1,405
5 votes
1 answer
154 views

Is environmental routing possible?

In the general.php config file, I can target settings for multi-environments like so: return array( '*' => array( 'devMode' => false ), '.loc' => array( 'devMode' => true ...
Mark Notton's user avatar
  • 2,337
5 votes
1 answer
478 views

"Subtemplates" for entry using routing?

Suppose I have a section for Products, that uses the template at products/_entry and is set up to have the URL format of 'products/{slug}'. Our existing page structure shows a Product page when you ...
Chad W's user avatar
  • 312
5 votes
1 answer
1k views

How can I implement advanced action routes (in routes.php)?

We want to mask specific action routes in our project's routes.php file. Currently what we have looks like this: return array( // /actions/api/element/section/name/{$name}/ 'api/test/(?P<...
Tyler Willingham's user avatar
4 votes
2 answers
2k views

Controller action redirection when called via route

I have a route set up in routes.php that calls a controller action using something similar to what is described here: https://straightupcraft.com/articles/how-do-i-setup-a-route-to-point-to-a-...
John O's user avatar
  • 391
4 votes
1 answer
1k views

Is the "registerSiteRoutes" hook screwing up my template path?

This may be a bug... I have a controller action which has been working great. It's a simple action with a single purpose... load a template with an internal value. public function actionMyAction() { ...
Lindsey D's user avatar
  • 24k
4 votes
1 answer
523 views

New route for entry types

I would like to create a route for the entry types of a specific section, pointing to a single template. Is it possible to do this automatically? So far I haven't had luck, I'm thinking something ...
cballenar's user avatar
  • 1,409
4 votes
1 answer
550 views

Simple template routes with plugins

I'm attempting to create a simple route that points to a template from a plugin. Note that I am attempting to create a page on the front-facing website, not the admin panel. Plugin (named: 'curious') ...
Jason's user avatar
  • 348
4 votes
1 answer
570 views

Redirect entry type to another domain

I have an entry type (outsideCourse) that will never need its own page. It only exists so I can manipulate it in various lists of required courses. Thanks to Mats Mikkel Rummelhoff, I have a macro to ...
Katie Fritz's user avatar
4 votes
1 answer
107 views

Bullet-proofing tags with punctuation

I have a route set up with a tag: news/tag/[tag] => news/_tag How do I generate urls that will match that route for all possible tags (including tags with punctuation)? How do I resolve that url ...
Marion Newlevant's user avatar
3 votes
3 answers
2k views

Routing within a single page app integration

I'm using Craft as the backend for an app and VueJS along with Element API to deliver the content. Everything so far is working sweet, except when I try to pull up the detail page for an entry ...
Steven Grant's user avatar
  • 1,855
3 votes
2 answers
840 views

How do I link an image to its own page?

I'm new to Craft CMS and can't figure out how to link images with the code below to its own page. Any suggestions? {% for asset in entry.mainImages %} <a href="{# link to the image's page #}"&...
jane's user avatar
  • 31
3 votes
1 answer
1k views

Get entry associated with current uri

If I am visiting /recipes/spaghetti which corresponds to an entry in a recipes entry type and the recipes/entry template, is there a way to directly get the current entry's data from within the ...
Augustine Calvino's user avatar
3 votes
1 answer
3k views

How do I create an advanced route with multiple slugs?

I'm trying to create a route for an RSS feed which allows for the following routes. domain/feed domain/category/feed domain/category/subcategory/feed I have the first two routes working and the ...
Seán O'Grady's user avatar
3 votes
1 answer
486 views

Plugin Routes: Asterisk Token effect from CP Routes

I'd like to use the asterisk token functionality that is available in the CP in my plugin. This way I can have an infinite amount of 'pages' under certain routes. In the CP, it looks like myroute/* ...
taylor's user avatar
  • 1,128
3 votes
1 answer
764 views

Non-CP routes in plugins

I'm building a custom plugin and need to have a publicly accessible (non-CP) route as part of the plugin. From what I've read I can use registerSiteRoutes() to register non-CP routes within my plugin....
Brett DeWoody's user avatar
3 votes
2 answers
808 views

Can I open one template/route when Craft is offline?

I've set Craft offline (System status). Is it possible to "open" one specific URL route so it can be accessed even though the website is offline? For example the route: /blog/post
naboovalley's user avatar
  • 2,844
3 votes
1 answer
118 views

Where do I begin troubleshooting a Form in Craft that is redirecting to /login on iPad and iPhone?

I'm not sure how to ask this question. I have a form. It works just fine on desktops. However when the form is submitted on iPhone or iPad it never makes it to my controller and resolves to the URL /...
Ben Parizek's user avatar
  • 13.5k
3 votes
1 answer
531 views

Route token that includes forward slashes

I'm setting up a route in control panel. I'd like to use a token that is similar to asterisk but involves forward slashes. Here's an example: I want to route everything from site.com/blog/* to a ...
Jure Srpcic's user avatar
3 votes
1 answer
194 views

Pagination / Custom Routes (Based on Entry Existing)

I've created a custom route for my entries based on week like so: 'events/(?P<year>\d{4})/(?P<week>\d{2})' => 'events/_weekindex', I know i can group entries by week like this: {% ...
Christopher Healey's user avatar
3 votes
1 answer
1k views

Limit entry pagination to 6 pages?

I've been given a site and asked to prevent visitors from seeing the news archive beyond page 6. The navigation has already been done, but if the user manually enters example.com/news/p7 they'll see ...
jezmck's user avatar
  • 143
3 votes
1 answer
1k views

Setting up redirects via Craft routes?

I'm trying to set up redirects for some pages (specifically pages in structure sections that are there purely for structure, which I want to redirect to their first child). Craft's "routes" seem to ...
Nick F's user avatar
  • 1,215
3 votes
1 answer
740 views

Multiple entry templates per entry

Is there a way to have multiple entry templates per entry? I'd like to create two different templates that display the same content/data in different ways.
Rob Erskine's user avatar
3 votes
2 answers
1k views

Catch-all routes based on template structure

I have many of the templates organized into sub-folders. E.g. /manager/entries/edit.html, /manager/users/edit.html etc. The site is using 4-segment URLs to access code in those templates, e.g. http://...
Yuri Salimovskiy's user avatar
3 votes
1 answer
476 views

Override a wildcard dynamic route template

I have a dynamic route for individual user /profiles. I expected it would be possible to override this route for /profiles/all but apparently not. This can be achieved in the template I expect, with ...
Rob's user avatar
  • 865
3 votes
1 answer
858 views

What's best practice for creating an index page for Channels?

If I have a section called "news" with section type "channel" with entries having their own URLs, what is best practice for creating an index for when people site.com/news? Do I just create an index ...
Danny's user avatar
  • 83
3 votes
1 answer
972 views

How do you handle routes in CP with Query Parameters?

I am currently setting up routes for a one-page application. As soon as a Query Parameter is introduced, the route fails. The route "test" replaces "my-av1" in the following photos. The documentation ...
Kristian S. Munkvold's user avatar
3 votes
1 answer
470 views

How do I toggle list/grid view on section index page without affect category filtering

I have a section "projects" with entry type (projectPage) with and an index page set up displaying a grid view of entries. I have also set up category filtering via links to the {{category.url}} ...
Micah Morgan's user avatar
2 votes
3 answers
858 views

Havin trouble with registerCpRoutes

I'm having trouble registering a CP route. What I have is a "working" SiteAdministrator_UserController.php (other form save actions already work through this controller, so its functional). Inside the ...
pythic's user avatar
  • 569
2 votes
2 answers
355 views

Prettify search URL

I can't find a way to clean up the search address from /search/?q=.../ to /search/query/. I see ways of getting the last segment of the url with something like craft.request.getSegment. My other ...
Kitsune's user avatar
  • 333
2 votes
2 answers
791 views

Best approach for building a webshop with more than one URL to the same product (entry)

What would be the best approach to a webshop in Craft, for solving the possibility of having products on more that on URL. Is there a best practice for one entry being accessible from more than one ...
oyvind-redrabbits's user avatar
2 votes
2 answers
3k views

How can I call a controller method from the front-end using ajax

I would like to call an action method from within my plugin via ajax but I am always getting a 404 response. I have a controller method that matches the ajax url: jquery $.ajax({ 'type': 'post'...
Damon's user avatar
  • 4,706
2 votes
2 answers
437 views

Create a route to display entries with multiple tags

I understand how to set up a route and template that allows me to display entries by tag. But how can I set up a template + route to grab multiple tags (if supplied but could just be one) from the ...
jamus's user avatar
  • 117
2 votes
2 answers
518 views

Wildcard subdomain for posts

I want to assign a wildcard domain to every entry from a specific type. For instance: client.example.com Where client is the slug of an entry. Is that possible? If yes, how? Thanks!
Jim's user avatar
  • 21
2 votes
2 answers
880 views

Multiple URL Formats per element type (Entries, Categories)

I suspect this boils down to a feature request, but I'll start here in case there are any other ideas. Basically, I want to be able to define multiple URL formats for a single section or category ...
Tim Kelty's user avatar
  • 3,081
2 votes
1 answer
734 views

How to troubleshoot routes

Very new to Craft CMS... My first route, which i think is very simple, is not working, i'm getting a 404 error. How can I troubleshoot routing? My settings: If the URI looks like this: databases/ ...
Bill French's user avatar
2 votes
1 answer
533 views

Can I open templates/routes other than 503 when Craft is offline?

I've set Craft offline (System status). Is it possible to "open" URL routes so it can be accessed even though the website is offline? Right now every request gets routed to my 503.html page. For ...
carlcs's user avatar
  • 36.3k
2 votes
1 answer
519 views

Using ajax with routes is it right?

So doing some entries loading via ajax from this question which I expanded on. https://craftcms.stackexchange.com/a/9868/3579 I'm curious about setting up a route for the actual ajax file since it ...
Bowenac's user avatar
  • 811
2 votes
1 answer
772 views

Dynamic routing via plugin with special characters

After learning how to use dynamic routing in MyPluginPlugin.php, I quickly ran into the issue of if the URL has special characters from url_encode: public function registerSiteRoutes() { return array(...
taylor's user avatar
  • 1,128
2 votes
1 answer
773 views

Is it possible to define optional route segments?

Is it possible to have optional route segments/variables with getCpRoutes() and getSiteRoutes()? I'd like the following route to work, even if the URI only contains one segment ("myplugin") rather ...
Mats Mikkel Rummelhoff's user avatar
2 votes
1 answer
374 views

Craft routing with extra attributes

I am Craft newbie, and am trying to use PayPal express checkout but am stuck on a confirmation route. How do I register a route like this: localhost:8888/app/confirm?token=EC-5UA33446UB5625646&...
Silvanus Matiku's user avatar