user2143356
user2143356

Reputation: 5597

Referencing Twig templates between two bundles in Symfony2

The only thing that I can't get working in the code below is that I want it to use the navigation.html.twig file that is located in the folders of the bundle that calls it. So in this example it's bundle 2. So is it possible to not hard-code the bundle path in it? Obviously I haven't hard-coded the path in my code, but it doesn't work like this (everything else does, it's just reference to the navigation.html.twig file).

Bundle 1 holds the main parent HTML/Twig and calls the navigation.html.twig file that is located in whichever bundle calls this file:

<! inside bundle 1 -->
<!DOCTYPE html>
<head>
<head>
<html>
<body>
<div id="navigation">
{% include 'navigation.html.twig' %}
</div>
<div id="content">
{% block the_content %}
{% endblock %}
</div>
</body>
</html>

Bundle 2 calls bundle 1:

{# inside bundle 2 #}

{% extends "Bundle1:index.html.twig" %}

{% block content %}
This is the content for this page
{% endblock %}

Upvotes: 2

Views: 587

Answers (1)

Jovan Perovic
Jovan Perovic

Reputation: 20193

As far as I know, it's not possible to skip hard-coding. However, if you move your file to /app/Resources/views/navigation.html.twig you could reference it via:

{% include '::navigation.html.twig' %}

BTW, just out of curiosity, why can't you have one "common" bundle which would hold shared templates(among other files)?

Upvotes: 1

Related Questions