Questions tagged [routes]

Questions about how Craft handles a request.

Filter by
Sorted by
Tagged with
8
votes
1answer
963 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....
2
votes
1answer
639 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 ...
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 ...
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 ...
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 ...
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() { ...
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
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 ...
5
votes
1answer
418 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 ...
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(...
1
vote
2answers
852 views

How do I redirect to a corresponding route when user switches languages?

I'm working on a multilingual site with english and spanish locales. I've built persistent switcher that resides in the site footer. When users click it, it redirects to a corresponding entry in the ...
1
vote
1answer
596 views

Use of tag.slug instead of tag.title in a custom route

I've followed this guide for creating a routes to list entries with specific tags. It is working fine except that I have muli-word tags so using the tag token from Settings -> Routes gives me urls ...
1
vote
1answer
128 views

Looping through returns nothing after using dynamic routes to get the entry type and category

I'll explain a bit of the structure of the content and then proceed to the issue. So i have a website with a shop in it with the url mysite.com/shop/, it is an channel section, and its template is ...
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<...
2
votes
1answer
405 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
428 views

Route that should be matching numbers not matching a zero?

I have the following in my routes.php file: return array( 'articles/(?P<sectionId>\d+)/(?P<offset>\d+)' => 'articles/index' ); And while localhost/articles/4/1, for example, ...
1
vote
1answer
227 views

Is it achievable to route a dynamic URI with prefixed character?

The goal is to have a variable(link) merged with prefix "any special character", that will not break the URL(this was pointed to my about character in URL lately, but in this question, We use "#"). So ...
1
vote
1answer
485 views

Resolving the $entry variable for custom routes somewhere but a Twig template

I have several custom routes defined on the routes.php and, as usual, I am resolving the value of the template's entry in the Twig template when it is not defined (which is when it doesn't match a ...