0
votes

[RESOLVED] I have Symfony app and I am using twig templates. When I run my app locally on my computer it works, but when I upload it on my hosting provider on some pages the <meta charset="UTF-8" /> and <title> tags from head go into body. This happens only on some twig templates and not all. Here is my base template

<!DOCTYPE html>
<html>
{% block head %}
    <head>
        <meta charset="UTF-8" />
        <title>{% block title %}Welcome!{% endblock %}</title>
        {% block stylesheets %}{% endblock %}
        <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
    </head>
{% endblock %}
    <body>
    <nav>
        <div class="container">
            {% if app.user %}
            <a href="{{ path('user_logout') }}">Изход</a>
            <a href="{{ path('zadanie_index') }}">Заявки</a>
                {% if (app.user.type == "Manager") or (app.user.type == "LittleBoss") %}
                    <a href="{{ path('zadanie_new') }}">Нова заявка</a>
                    {% endif %}
            {% else %}
            <a href="{{ path('homepage') }}">Home</a>
            <a href="{{ path('user_login') }}">Вход</a>
            {% endif %}
        </div>

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

It is a valid html and it works. Every view extends base and overrides block body and that is all they do. Here is my new.html.twig which works both locally and on the server

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

{% block body %}
    <h1>Нова заявка</h1>

    {{ form_start(form) }}
        {{ form_widget(form) }}
        <input type="submit" value="Create" />
    {{ form_end(form) }}

    <ul>
        <li>
            <a href="{{ path('zadanie_index') }}">Върни се към списъка със заявки</a>
        </li>
    </ul>
{% endblock %}

Pretty simple - it extends base and overrides block body and that is it. Now here is the code in index.html.twig where meta tag goes into body. Bear in mind that both files are in the same folder and they extend the same base file.

{% extends 'base.html.twig' %}
{% block body %}
    <h1>Заявки</h1>

    <table>
        <thead>
            <tr>
                <th>Отдел</th>
                <th>От</th>
                <th>Вид</th>
                <th>Описание</th>
                <th>Краен Срок</th>
                <th>Дата</th>
                <th>Дизайнер</th>
                <th>Подизпълнител</th>
                <th>Приключил</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
        {% for zadanie in zadanies %}
            <tr style="background-color:{{ zadanie.backgroundColor }}">
                <td>{{ zadanie.department }}</td>
                <td>{{ zadanie.fromUser }}</td>
                <td>{{ zadanie.typeTask }}</td>
                <td>{{ zadanie.description }}</td>
                <td>{% if zadanie.term %}{{ zadanie.term|date('Y-m-d H:i:s') }}{% endif %}</td>
                <td>{% if zadanie.date %}{{ zadanie.date|date('Y-m-d H:i:s') }}{% endif %}</td>
                <td>{{ zadanie.designer }}</td>
                <td>{{ zadanie.executioner }}</td>
                <td>{% if zadanie.isOver %}Yes{% else %}No{% endif %}</td>
                <td>
                    <ul>
                        <li>
                            <a href="{{ path('zadanie_show', { 'id': zadanie.id }) }}">show</a>
                        </li>
                        <li>
                            <a href="{{ path('zadanie_edit', { 'id': zadanie.id }) }}">edit</a>
                        </li>
                    </ul>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    <ul>
        <li>
            <a href="{{ path('zadanie_new') }}">Създай нова заявка</a>
        </li>
    </ul>
{% endblock %}

There is some part written in bulgarian (cirillic) which u might not be able to read, but it has nothing to do with the logic. They are purely static. This file again extends base and overrides body. For some reason with this code when I run it on the server here is what I get:

and here is what I get when I run it locally:

The code is the same. And if you are asking about the server - they told me they are not familiar with Symfony and can't help me with my problem. So I just know they have PHP 7.1 and can run Symfony app and I also know something is broken. If you can't help me fix it by changing the code please tell me what should I say to my hosting provider

Turned out i had a dump() in my controller and for some reason it broke everything

1
Здравей колега! This is an odd issue which I have never experienced. Try clearing your cache from var/cache. If that doesn't help - make absolutely sure that the twig files as well as the php code you're writing is actually being done in UTF-8! You can check that in your IDE. :)tftd
As for the hosting - if it's superhosting or host.bg it should "just work". I've used them with many applications written using symfony.tftd
@Pavlin Petkov, can you try to replace the content of body block in index.html.twig with just some test phrase in it? Just to check if the content has something to do with this issue. If with test it works fine then try to add the <h1> to see if the language is the issue.TheFrost
Thank you all. Turned out that in my controller for some reason there was a dump(); that I havent seen and somehow it broke everything. Removed the dump(); and it was all fixed.Pavlin Petkov

1 Answers

0
votes

As stated in the comments I had a dump() which broke everything. Removed it and it was all gucci.