Skip to content

allow Template attributes 'template','block' to accept an Expression and null, pass route info #58267

Open
@tacman

Description

@tacman

Description

I like the #[Template()] attribute when configuring controllers, and I'm excited to see the option to render just a block within the template.

I'd like to be able to define both the template and the block using the Symfony Expression Language. I'd like the request information passed, as that's often what I'm using to decide what template/block to render. For completeness, the security context would be nice too.

Example

(not sure what the 'context' is here)

    #[Template(new Expression(
        '"ROLE_ADMIN" in role_names or (is_authenticated() and user.isSuperAdmin()) 
or (context.request.query.get("admin_view")' 
          ? 'admin/talk.html.twig' 
          : 'visitor/talk.html.twig',
    ))]

Ditto for the 'block' parameter. If the block parameter (new in 7.2!) accepted null (or false), then it should be treated as the same as if it weren't passed (so rendering the template normally).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions