M
M
magary42016-08-09 09:59:20
symfony
magary4, 2016-08-09 09:59:20

Template loading depending on content type?

Now so

public function indexAction() 
{
  ....
  $content = $this->contentService->find(..)

  if($content->type ....)
   тут много разных проверок которые определяют какой темплейт должен быть использован для данного контента

  return $this->render(  ,  [ "content" => $content ])
}

how to do it wisely
I see the following options:
1 custom twig loader
2 helper $this->get('tpl.helper')->getTemplate($content);
3 inherit from the controller and implement its own $this->render method that will do it
4 find some event if there is one, and listen to it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shagguboy, 2016-08-10
@magary4

if the checks are of the same type, then they should be placed in $content->type
something like this $content->getType()->getTemplate()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question