public function getSubstituteForView(View $view)
    {
        foreach ($this->getContextualSubstitutes() as $substitute) {
            if ($substitute->getView() === $view) {
                return $substitute;
            }

            while ($template = $view->getTemplate()) {
                if ($substitute->getView() === $template) {
                    return $substitute;
                }
            }
        }
    }