17/05/2015 - TWIG
Twig şablonlarını birbirlerine bağlama işlemi {% extends 'bundle:folder:template' %}
ile yapılır ama ya klasör yapımız biraz karışıksa! Bu gibi durumlarda {{ parent() }}
işimize yarar.
sport
app
Resources
views
default
base.html.twig
src
Football
BackendBundle
....
FrontendBundle
Resources
views
Country
list.html.twig
index.html.twig
Default
index.html.twig
Aşağıdaki {{ parent() }}
satırlara dikkat edin.
# sport/app/Resources/views/base.html.twig
<body>
<a href="{{ path('football_frontend_default_index') }}">FRONTEND</a>
‐
<a href="{{ path('football_backend_default_index') }}">BACKEND</a>
<hr />
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
</body>
# sport/src/Football/FrontendBundle/Resources/views/Default/index.html.twig
{% extends '::base.html.twig' %}
{% block body %}
{% spaceless %}
<a href="{{ path('football_frontend_country_index') }}">COUNTRY</a>
|
<a href="{{ path('football_frontend_country_index') }}">LEAGUE</a>
<hr />
{% endspaceless %}
{% endblock %}
# sport/src/Football/FrontendBundle/Resources/views/Country/index.html.twig
{% extends 'FootballFrontendBundle:Default:index.html.twig' %}
{% block body %}
{% spaceless %}
{{ parent() }}
<a href="{{ path('football_frontend_country_index') }}">Index</a>
|
<a href="{{ path('football_frontend_country_list') }}">List</a>
|
<a href="{{ path('football_frontend_country_create') }}">Create</a>
<hr />
{% endspaceless %}
{% endblock %}
# sport/src/Football/FrontendBundle/Resources/views/Country/list.html.twig
{% extends 'FootballFrontendBundle:Country:index.html.twig' %}
{% block body %}
{% spaceless %}
{{ parent() }}
COUNTRY - List
{% endspaceless %}
{% endblock %}
FRONTEND - BACKEND
-------------------------
COUNTRY | LEAGUE
-------------------------
Index | List | Create
-------------------------
COUNTRY - List