Hot answers tagged

10 votes
Accepted

Is it possible to route to www.site.com/username?

I would not particularly advise creating a uri pattern that was just 'www.site.com/username' because usernames can essentially be anything which might cause routing conflicts (i.e. if the username is '...
9 votes
Accepted

Is it possible to route a subdomain to specific template group?

For this example we have two domains: http://www.example.com http://subdomain.example.com To use different templates for the subdomain, we can accomplished this with these steps: 1) Setup subdomain ...
  • 13.3k
8 votes
Accepted

Show entry in channel based on URL segment

You can retrieve the entry by grabbing it from the URL as a variable: {% set entrySlug = craft.request.lastSegment %} And then using craft.entries to find the matching content: {% set entry = craft....
8 votes
Accepted

How to set a channel as the homepage

You can do this with Craft’s {% redirect %} tag. Just put this in your /index.html template: {% redirect 'news' %} If you want to redirect to the latest entry in your News section, as you mentioned ...
7 votes
Accepted

Cannot post data to a plugin controller action

There's alot of different things that could be going on here. First, if your action is named actionPayWithPaypal (as in the code above) the action url should be paypalPayments/payment/payWithPaypal I ...
  • 7,248
7 votes
Accepted

Rendering templates from plugin controller

Figured it out! I went ahead and took at look at how Craft's renderTemplate method works which cleared it up for me. A few things... Craft caches CSS/JS resources inside of getHeadHtml() and ...
  • 345
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" ...
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 ...
6 votes
Accepted

"Subtemplates" for entry using routing?

You might check out the routing docs on accessing subpatterns in your templates. Here is the example given in the docs (which provides the variables 'year' and 'month' to the template that correspond ...
6 votes

Show entry in channel based on URL segment

Alan describes how to setup a route via the Settings->Routes area in the CP. If you happen to be managing file based routes you can setup a similar route like so: return array( // Your Custom ...
  • 13.3k
6 votes

Prevent ALL templates from being rendered directly?

This is very, very simple to do... just put every single template into a specific folder, then prefix the folder with an underscore: /craft/templates/_everything/ Template files beginning with ...
  • 23.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'] );
6 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/...
  • 11.1k
5 votes
Accepted

All templates automatically private

Your templates will be private if they are contained in a folder prefixed with a "_"... So just make a folder like that, and put everything else inside of it: /craft/templates/_everything/...
  • 23.6k
5 votes
Accepted

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

Yes it’s possible. First you will need to update your route key so that you’re capturing the name parameter with a valid named subpattern. (You were close, but missing the actual pattern part of it). ...
5 votes

Multi-Domain routing

To do this, copy index.php and .htaccess from a.com’s webroot into b.com’s, and make sure the $craftPath variable is correct. Then, around where $craftPath is getting defined, override $_GET['p'] to ...
5 votes
Accepted

Direct access call for a twig template from a twig template gives 404

Not sure exactly what you trying to do here? Call a Twig template from Angular? Twig is a server side technology, Angular is getting parsed on the client side. The only way Craft is going to parse a ...
  • 6,502
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 ...
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 ...
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 ...
5 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 ...
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 ...
  • 203
4 votes

How to set a channel as the homepage

If you want one of your channel entries to be the homepage, simply include the channel entries' template to your home page index.html: {# Set the `entry` variable manually #} {% set entry = craft....
  • 35.9k
4 votes

Working with Structure & Multiple Pagetypes

Assuming that those pages are working off of different entry types, you should check out this great help article... How can I give each Entry Type its own template? Basically, you let a parent ...
  • 23.6k
4 votes

How to use url segments like with Freebie in EE

One easy way to work around this is to use a query string instead of a segment. You'd redirect the user to for instance /contact?receipt=thanks instead of /contact/thanks, and you change the ...
  • 7,248
4 votes
Accepted

Redirects or Routing for Landing Page URL's?

You can either set the URL Format of the landing pages channel to {slug} (the same as your normal pages) Or you could try putting the landing pages in the normal pages structure, but give them a new ...
  • 566
4 votes
Accepted

Route token that includes forward slashes

The CP route settings don’t have a token for matching multiple URI segments. However you can pull it off from craft/config/routes.php instead: return array( 'blog/(.+)' => 'path/to/template', )...
4 votes
Accepted

Controller Action 404

When your plugin has a camel cased name you need to make sure you camel case your references to it, such as when you try and visit an action url. I assume this is due to when craft tries to resolve ...
  • 4,519
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.
  • 66.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 ...
  • 4,361

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