Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

getActiveRenderPath() directly in view


How can I, from inside the view, get the name of the file being rendered ?

var_dump($this->view->getActiveRenderPath()); returns NULL.

Thank you.


// Controller
 public function indexAction()
        echo $this->view->getViewsDir().$this->dispatcher->getControllerName().'/'.$this->dispatcher->getActionName();
edited Jun '16

Thank you. But what if I $this->view->pick() another template from the action ? What I'm tried to get is really which file is being rendered regardless of what's the current controller/action.

edited Jun '16

You can use the beforeRenderView event to retrieve the path of the view that's being rendered. Inside that same event handler you can then pass the path as a view variable:


$eventsManager->attach('view:beforeRenderView', function ($event, $view, $path) {
    $view->setVar('activeRenderPath', $path);

And inside your view: {{ activeRenderPath }}

And here's an example on how to use the event manager:

Great ! Works perfectly, thank you.