Questions tagged [routes]

Questions about how Craft handles a request.

Filter by
Sorted by
Tagged with
9
votes
2answers
7k 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 ...
8
votes
1answer
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 ...
8
votes
1answer
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 ...
7
votes
1answer
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 ...
7
votes
1answer
961 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....
6
votes
2answers
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 ...
6
votes
1answer
930 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 ...
6
votes
2answers
2k 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 ...
6
votes
1answer
629 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 ...
5
votes
2answers
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/<...
5
votes
1answer
128 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 ...
5
votes
1answer
417 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 ...
5
votes
1answer
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<...
5
votes
1answer
476 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') ...
4
votes
2answers
599 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 #}"&...
4
votes
1answer
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() { ...
4
votes
1answer
456 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 ...
4
votes
1answer
389 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 ...
4
votes
1answer
98 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 ...
3
votes
3answers
1k 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 ...
3
votes
2answers
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'...
3
votes
1answer
2k 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 ...
3
votes
1answer
454 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/* ...
3
votes
1answer
738 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....
3
votes
2answers
535 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
3
votes
1answer
104 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 /...
3
votes
2answers
1k 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-...
3
votes
1answer
423 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 ...
3
votes
1answer
181 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: {% ...
3
votes
1answer
898 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 ...
3
votes
1answer
714 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.
3
votes
2answers
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://...
3
votes
1answer
383 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 ...
3
votes
1answer
836 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 ...
3
votes
1answer
890 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 ...
3
votes
1answer
596 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 ...
3
votes
1answer
433 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}} ...
2
votes
3answers
817 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 ...
2
votes
2answers
262 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 ...
2
votes
2answers
755 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 ...
2
votes
2answers
422 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 ...
2
votes
2answers
676 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 ...
2
votes
1answer
624 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/ ...
2
votes
1answer
404 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 ...
2
votes
1answer
497 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 ...
2
votes
1answer
694 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(...
2
votes
1answer
637 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 ...
2
votes
1answer
335 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&...
2
votes
1answer
282 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!
2
votes
2answers
443 views

Passing data back to form on invalid submission

I currently have a form that is being displayed to the user via a custom route. The form submits to a controller. The first thing the controller does is populate a custom model and validates it. If ...