0

I am working with sulu cms and symfony. Just started with the project. This is my base.html.twig

<!DOCTYPE html>
<html lang="{{ app.request.locale|split('_')[0] }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

{% block meta %}
    {% include "@SuluWebsite/Extension/seo.html.twig" with {
        "seo": extension.seo|default([]),
        "content": content|default([]),
        "localizations": localizations|default([]),
        "shadowBaseLocale": shadowBaseLocale|default(),
    } %}
{% endblock %}

{% block style %}{% endblock %}
</head>
<body>
<header>
    {% block header %}
        <nav>
        </nav>
    {% endblock %}
</header>

<form action="{{ path('sulu_search.website_search') }}" method="GET">
    <input name="q" type="text" placeholder="Search"/>
    <input type="submit" value="Go"/>
</form>

<main>
    {% block content %}{% endblock %}
</main>

<footer>
    {% block footer %}
        <p>Copyright {{ 'now'|date('Y') }} SULU</p>
    {% endblock %}
</footer>

{% block javascripts %}{% endblock %}
</body>
</html>

And I extend it in event.html.twig

{% extends "base.html.twig" %}

{% block content %}
<h1>This is Event Template</h1>
<h1>{{ content.title }}</h1>
<h2>{{ content.subtitle }}</h2>

{% for image in content.photo %}
    <img src="{{ image.thumbnails['500x'] }}" alt="{{ image.title }}" title="{{ image.description|default(image.title) }}">
{% endfor %}
{% endblock %}

But the rendered page only shows the child content

<h1>This is Event Template</h1>
<h1>Veranstaltungstitel</h1>
<h2></h2>

What could be the reason, that the parent base template is not rendered? Could not find anything like this with google.

UPDATE

I am on a Windows 10 Pro computer and I cloned a git repository with a sulu cms / symfony project that someone else made on a Linux system.

I changed the .env file to APP_ENV=dev

I am running the project on Apache (MAMP) and with a mysql (MAMP) database. The database is connected, I can see the data in the admin panel and see changed data in the database with phpmyadmin.

On my computer Symfony CLI version v4.26.11 is installed.

  • 1
    Did you clear the cache after you've modified the `base`? – DarkBee Dec 16 '21 at 10:37
  • Yes, I cleared the cache. –  Dec 16 '21 at 11:36
  • 1
    Other than that, I've have no explanation and can't reproduce this. Are you extending the correct `base` template – DarkBee Dec 16 '21 at 11:46
  • Yes, I am extending the correct base template. –  Dec 16 '21 at 12:07
  • @guteFee Can you provide relative paths to `base.html.twig` and `event.html.twig`? What is the version of Symfony? – Jovan Perovic Dec 16 '21 at 12:31
  • The path to base.html.twig is: templates/base.html.twig The path to event.html.twig is: templates/pages/event.html.twig Symfony CLI version v4.26.11 That is suprising me. I thought I had Symfony 5.4.0. Maybe that is causing the problem. –  Dec 16 '21 at 13:59

2 Answers2

0

Did you create the sulu project using the create-project command like in the docs. Then you should be under dev environment. Check that by go into your local .env.local and check if there it is set to APP_ENV=dev so changes will automatically be detected and no cache clear is required. This is for development only!!!

If you are on a prod server make sure the clear all cache. This includes admin and website cache:

bin/adminconsole cache:clear
bin/website cache:clear

If that still does not help check if any edit of a twig template does effect anything in your frontend. Try also to remove all caches by removing the var/cache directory:

rm -rf var/cache

If that is not the case its a hint that your machine or server has opcache activated and all your PHP files are cached. If you are on a development machine you should configure opcache to check for file timestamps see:

https://www.php.net/manual/de/opcache.configuration.php#ini.opcache.validate-timestamps

If you are on production server where it does restart your webserver and/or php processes or use a cachetool like:

https://github.com/gordalina/cachetool

To clear that caches.

Alexander Schranz
  • 2,154
  • 2
  • 25
  • 42
  • Thank you for your quick response. Even though I set it to APP_ENV=dev in .env I cleared the caches. The caches are cleared but an error pops up stating that there is not enough memory. I set the php.ini for console and Apache php to 128M. Now I disabled opcache opcache.enable = 0 in the php.ini and restarted server. Makes no difference. –  Dec 16 '21 at 15:57
  • Try to use the php internal webserver for development. See: https://docs.sulu.io/en/2.3/book/getting-started.html#start-a-web-server – Alexander Schranz Dec 17 '21 at 09:36
  • I need three virtal hosts with the website, that is the reason I use the Apache (MAMP). Also sulu does read the base.html.twig template (throws an error if it can not find it) BUT does not render it. –  Dec 17 '21 at 15:39
0

The reason that the base.html.twig page was not rendered was that the theme templates are overriding the default theme.