symfony - Require a Twig Block Be Defined in a Child -


i have <title> tag defined block in base twig file , want make sure views override block. there way mark block required error if forget?

this isn't built twig (maybe should make feature request!)

there 1 way can think of, it's not using blocks.

if have base.html.twig of, let's quick example:

<title>{% block title %}{{ title }}{% endblock %}</title> 

and extend block:

{% extends '::base.html.twig' %} 

but don't declare {% block title %} - twig throw notice in development environment (and in prod.log in production environment) unset variable. (you shouldn't want symfony throw error in production trivial this.)

then there's 2 ways of "satisfying requirement":

  1. pass title variable extended twig file
  2. override title block own contents

example 1, in controller:

return $this->render('acmebundle:extended:view.html.twig', array(     'title' => 'my fancy title' )); 

example 2, in twig file:

{% extends 'acmebundle::base.html.twig' %}  {% block title %}my fancy title{% endblock %} 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -