0
votes

If i have AlphaBunde that is parent of BetaBundle how can i extend a twig block without overriding the entire template?

How can i import the routes that exist only in BetaBundle?

2

2 Answers

3
votes

You cannot extend a block in Twig. You can overload it if you extend a template (and call parent() which kind of works as inheritance).

If you extend bundle you can overload its controllers or resources. I don't think you can really extend a template from a parent bundle because of how the paths are resolved. You can read more about it in the Extending a Bundle documentation chapter.

Also, How to use Bundle Inheritance to Override parts of a Bundle might clarify few things.

Remember to check Overriding Bundle Templates to learn how to overload templates in an application.

About routes: I think you'll have to define each route in your application's configuration file if you want to import them selectively.

0
votes

If you want to use template from another bundle and you do not want to override whole template you use this:

// Your file in ProjectAplhaBundle index.html.twig

{% extends "ProjectBetaBundle::layout.html.twig" %}

{% block content %}
    {{ parent() }}
    Somethings added to the existing content    
{% endblock %}

For routing from just BetaBundle remove all routes (routing.yml in app folder) and leave just one with something like this:

ProjectBetaBundle:
    resource: "@ProjectBetaBundle/Resources/config/routing.yml"
    prefix:   /

Then you specify all your routes in @ProjectBetaBundle/Resources/config/routing.yml

I hope that helps. Cheers