-
Notifications
You must be signed in to change notification settings - Fork 645
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Give sections an option to route to a controller not just a template #2450
Comments
Meant to say also that the entry that's normally pre-loaded as a variable available in Twig could be an incoming route parameter or attached to the route object in some way. |
I’ve thought about this, but unsure whether enough people would want it, to be worth the added UI complexity. You can take over elements’ routing though, using the use craft\base\Element;
use craft\events\SetElementRouteEvent;
use yii\base\Event;
Event::on(Element::class, Element::EVENT_SET_ROUTE, function(SetElementRouteEvent $e) {
/** @var Element $element */
$element = $e->sender;
$params = [
'element' => $element,
];
$e->route = ['dev/locations/entry', $params];
}); |
Very helpful, thanks! The only additional argument I'll make in favor of the feature request is perhaps maybe having the route start with a keyword Craft can look for, no additional UI needed. Maybe something like |
Not a bad idea! |
Played around with it. Issue with supporting the template path being set with something Probably something like this: |
Don't forget about #1489 when thinking about updates to routes. 😉 |
Good point @carlcs. |
@brandonkelly given your piece of code: I routed it onto a module controller, but the params aren't being set as controller action arguments. |
Nevermind that @brandonkelly. UrlManager will do the trick: |
@gijsstegehuis Any parameters that match the names of your controller action arguments will be passed to those. So you could do this: public function actionEntry(\craft\base\ElementInterface $element)
{
// $element will be whatever $params['element'] was in the route
} |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
With Craft 3 we can have a custom module for site specific features, controllers, services, twig extensions, you name it. And it's AAAAAMAZING. However, one thing that's bugging me is this: I've worked on (and am working on currently) sites where every page needs to run through custom controllers to make sure custom variables are set, custom logic is run etc. I've jumped through elaborate hoops to make this work in Craft 2. But in Craft 3, it seems to me there's an opportunity to allow routing to a custom Yii controller as an option and not just a template. If we could specify the controller and method a section should run for the entry's URL in the same way we can specify a Yii controller in a route (for instance
dev/locations/entry
in the case of a site I'm working on right now, that would be super duper fantastic.So basically, as a feature request, anywhere we can tell Craft in the CMS to route a URI to a template, also give us the option to route to a controller action.
The text was updated successfully, but these errors were encountered: