Skip to main content

Questions tagged [routes]

Questions about how Craft handles a request.

Filter by
Sorted by
Tagged with
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
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
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
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
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
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
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
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
2 votes
1 answer
485 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, ...
Patrick Harrington'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
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
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
1 vote
2 answers
956 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 ...
Adam Snetman's user avatar
1 vote
1 answer
680 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 ...
Rosana Ruiz's user avatar
1 vote
1 answer
184 views

Can some one explain Event rules in plugins

So here is what I see in a controller: $event->rules['cpActionTrigger1'] = 'plugin/default/do-something'; What does the first part 'cpActionTrigger1' refer to and what does the second part refer ...
joomkit's user avatar
  • 2,034
1 vote
1 answer
106 views

Website transfer places /web in all urls, cs and js not loaded when moved up directory

I just transfered my website from one server to one.com. Now nothing works anymore cuz apparently one.com wants the index.php in the root directory but my index.php is in the "web" directory....
Masary's user avatar
  • 11
1 vote
1 answer
746 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 ...
Andrew Staroscik's user avatar
1 vote
1 answer
136 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 ...
Samuel E.'s user avatar
  • 239
0 votes
1 answer
237 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 ...
Dominik Krulak's user avatar