Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:23:03+00:00 2026-05-27T10:23:03+00:00

Take for example the following controller/action: public function indexAction() { return $this->render(‘TestBundle:TestController:index.html.twig’); } I

  • 0

Take for example the following controller/action:

public function indexAction()
{   
    return $this->render('TestBundle:TestController:index.html.twig');
}

I would like to write the template expression (or whatever it’s name is) this way:

public function indexAction()
{   
    return $this->render('*:TestController:index.html.twig');
}

So that symfony knows I’m looking for a template in this very bundle. Having to write the whole Owner + Bundle for every template/action/repository I want to refer is very annoying. Even more so considering most of the time I refer to actions and templates in the same bundle.

NOTE: I know templates can be put at the app level and be refernced like this:

'::index.html.twig'

But that is not what I need.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:23:04+00:00Added an answer on May 27, 2026 at 10:23 am

    It’s possible with a bit of custom code.

    Basically, you want to override the controller’s render() method and include logic to fetch the name of the current bundle.

    Note that instead of my controllers extending Symfony\Bundle\FrameworkBundle\Controller\Controller, they extend a custom controller (which then extends Symfony’s controller). This allows you to conveniently give the controller more ability by adding your own methods.

    Ex:
    MyBundle\Controller\MyController\ extends MyCustomBaseController which extends Symfony\Bundle\FrameworkBundle\Controller\Controller.

    So, in my custom controller I have these two methods:

    public function render($view, array $parameters = array(), Response $response = null) {
        $currentBundle = $this->getCurrentBundle();
        $view = str_replace('*', $currentBundle, $view);
        return parent::render($view, $parameters, $response);
    }
    
    public function getCurrentBundle() {
        $controller = $this->getRequest()->attributes->get('_controller');
        $splitController = explode('\\', $controller);
        return $splitController[1];
    }
    

    Take a look at render(). It fetches the current bundle name and uses it to build the $view variable. Then it just calls parent::render() and it’s as if you had manually defined the bundle name in the render statement.

    The code here is very simple, so you should be able to easily extend it to do other things, such as allow you to also avoid typing the controller name.

    Important: If you do use a custom controller, make sure you use Symfony\Component\HttpFoundation\Response, otherwise PHP will complain that the method signatures for render() don’t match.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take the following example plugin: (function($) { $.fn.alertOnClick = function(text) { return this.each(function(){ $(this).click(alert(text));
Take the following example, I have a class public class SomeItem { public string
Take the following generics example import java.util.List; import java.util.ArrayList; public class GenericsTest { private
Take the following class as an example: class Sometype { int someValue; public Sometype(int
I am just wondering to take the following example: public void main() { int
Take the following example, preg_match_all(/(^|-)[a-z]+(-|$)/i, foo-bar-moo, $matches); This (correctly) returns the following matches, foo-
Take for example following code from a class: public class Employee : IEntity {
Take for example the following regex match. preg_match('!^publisher/([A-Za-z0-9\-\_]+)/([0-9]+)/([0-9]{4})-(january|february|march|april|may|june|july|august|september|october|november|december):([0-9]{1,2})-([0-9]{1,2})/([A-Za-z0-9\-\_]+)/([0-9]+)(/page-[0-9]+)?$!', 'publisher/news/1/2010-march:03-23/test_title/1/page-1', $matches); print_r($matches); It produces the
Let's take for example a single file committed in CVS with the following history.
Take the following code for example; if (Convert.ToString(frm.WindowState) == Minimized) Layout.WindowState = Maximized; else

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.