我想在用户进入此页面时执行javascript:page1.twig.html
{% extends "Test1Bundle::layout1.html.twig" %}
// block code javascript here
{% block content %}
<div>
<span>Alexa .</span>
</div>
{% endblock %}
layout1.html.twig:
{% extends 'Test1Bundle::layout2.html.twig' %}
<p>
My name is : {% block content %}{% content %}
</p>
layout2.html.twig:
<!DOCTYPE html>
<html lang="fr">
<head>
// call block javascript here
</head>
.
.
.
我不知道我为此做了什么以及使用哪种功能!请帮忙!
答案 0 :(得分:1)
您需要在父母中定义空块,以便查看所呈现的内容:
page1.html.twig :
{% extends "layout1.html.twig" %}
{% block script %}
<script type="text/javascript">
// whatever
</script>
{% endblock %}
{% block name %}
<div>
<span>Alexa .</span>
</div>
{% endblock %}
layout1.html.twig :
{% extends 'layout2.html.twig' %}
{% block content %}
<p>
My name is : {% block name %}{% endblock %}
</p>
{% endblock %}
layout2.html.twig :
<!DOCTYPE html>
<html lang="fr">
<head>
{# btw, scripts are better at the bottom of the body #}
{% block script %}{% endblock %}
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>