We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Is there Config file based template routing?

Development and Programming

User BULfYYMv's avatar
User BULfYYMv
80 posts
5 days ago
User BULfYYMv's avatar User BULfYYMv

Is there a routes.php file that we could use to set template routes in code instead of via the cp?

There’s just a few instances where this would be really nice.

       
mithra62's avatar
mithra62
66 posts
5 days ago
mithra62's avatar mithra62

oooh, I likes it

       
mithra62's avatar
mithra62
66 posts
5 days ago
mithra62's avatar mithra62

not sure it exists yet, but damn, that’s a solid idea

       
User BULfYYMv's avatar
User BULfYYMv
80 posts
5 days ago
User BULfYYMv's avatar User BULfYYMv

I think eexecutive had that feature

       
User BULfYYMv's avatar
User BULfYYMv
80 posts
5 days ago
User BULfYYMv's avatar User BULfYYMv

but looking for something not requiring a big addon

       
mithra62's avatar
mithra62
66 posts
5 days ago
mithra62's avatar mithra62

yeah, can think of a couple ways to do this with an Add-on, but is probably too heavy handed

       
Bryan's avatar
Bryan
27 posts
5 days ago
Bryan's avatar Bryan

You can do this in your config.php

$config['enable_template_routes'] = 'y';


// template_name => url_pattern
$config['routes'] = [
    'blog/index' => '/blarg',
    'blog/entry' => '/blarg/{url_title}',
];

Everyone’s always looking for my blarg 🏴‍☠️

       
Tom Jaeger's avatar
Tom Jaeger
497 posts
5 days ago
Tom Jaeger's avatar Tom Jaeger

you can use regex as well

$config['routes'] = [
    'blog/article' => 'news/{slug:regex[#^[a-z0-9-]+$#]}',
    'blog/year'    => 'archive/{year:regex[#^(19|20)\d{2}$#]}',
];
       
User BULfYYMv's avatar
User BULfYYMv
80 posts
5 days ago
User BULfYYMv's avatar User BULfYYMv

feature request: delete routes from cp

       
User BULfYYMv's avatar
User BULfYYMv
80 posts
5 days ago
User BULfYYMv's avatar User BULfYYMv

no longer needed

       
Tom Jaeger's avatar
Tom Jaeger
497 posts
5 days ago
Tom Jaeger's avatar Tom Jaeger

LOL

       
User BULfYYMv's avatar
User BULfYYMv
80 posts
5 days ago
User BULfYYMv's avatar User BULfYYMv

adding this to my boilerplate btw

       
User BULfYYMv's avatar
User BULfYYMv
80 posts
5 days ago
User BULfYYMv's avatar User BULfYYMv

config.routes.php

       
Bryan's avatar
Bryan
27 posts
5 days ago
Bryan's avatar Bryan

Very nice! You should give a talk on how you build sites at the next conference 😉

       
User BULfYYMv's avatar
User BULfYYMv
80 posts
5 days ago
User BULfYYMv's avatar User BULfYYMv

Cool… when you add the routes array in your config it removes the UI from the cp.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.