John Davidson

php - Twig templates don't show updates. Symfony 4.3

0 comments
Message:


After I edit my twig templates, they don't load on the page.


I have a header and footer twig file which are included in my base.html.twig.
When i edit these files, the changes aren't pushed trough when i reload the page.
I've tried clearing the cache and i disabled cache in config\packages\twig.yaml


I even tried to completely delete the cache folder, nothing seems to work.


I use the built in Symfony server.


homepageController.php:


?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use App\Entity\Vacature;

/**
* @Route("/")
*/
class HomepageController extends AbstractController
{
/**
* @Route("/", name="homepage")
* @Template()
*/
public function index()
{
$rep = $this->getDoctrine()->getRepository(Vacature::class);
$data1 = $rep->getAllVacatures();
$data2 = $rep->getLastVacatures(5);

return array("carousel" => $data1, "laatste5" => $data2);
}
}

Homepage/index.html.twig


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

{% block title %}Hello HomepageController!{% endblock %}

{% block body %}
{% for vacature in carousel %}
<div class="vacature">
<h4>{{ vacature.titel }}</h4>
<p>{{ vacature.tekst }}
<a href="{{ path('vacature', { "id": vacature.id}) }}">Bekijk</a>
</div>
{% endfor %}
{% for vacature in laatste5 %}
<div class="vacature">
<h4>{{ vacature.titel }}</h4>
<p>{{ vacature.tekst }}
<a href="{{ path('vacature', { "id": vacature.id}) }}">Bekijk</a>
</div>
{% endfor %}
<pre>
{{ dump(carousel) }}
</pre>
{% endblock %}

base.html.twig


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}VacIT{% endblock %}</title>
<link href="{{ asset('/assets/css/foundation.css') }}" rel="stylesheet"/>
<link href="{{ asset('/assets/css/main.css') }}" rel="stylesheet"/>
{% block stylesheets %}{% endblock %}
</head>
<body>
<div id='header'>
{% include "header.html.twig" %}
</div>
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
<div id='footer'>
{% include "footer.html.twig" %}
</div>
</body>
</html>

header.html.twig


<div class='header'>
<div class="row">
<div class="small-12 columns">
<div class='header-logo'>
<a href="{{ path('homepage') }}">
<img id='logo' src="{{ asset('/assets/images/logo/logo.png') }}" alt="logo" width="200px">
</a>
</div>
<div class="skew-header-shadow">
<div class="skew-header"> </div>
</div>
</div>
</div>
</div>

footer.html.twig


<div class="footer-box">
<div class="skew-footer-shadow">
<div class="skew-footer"> </div>
</div>

<div class="footer">
<a href="{{ path('homepage') }}">
<img id='logo' src="{{ asset('/assets/images/logo/logo.png') }}" alt="logo" width="300px">
</a>
</div>
</div>

the tree is


Project
|-bin
|-config
|-public
|-assets
|-CSS
|-Fonts
|-images
|-logo
|-src
|-Command
|-Controller
|-Entity
|-Repository
|-Resources
|-templates
|-homepage
|-index.html.twig
base.html.twig
header.html.twig
footer.html.twig

Edit: I thought maybe this could be the reason somehow, the entire folder was inside my OneDrive. The thought crossed my mind, OneDrive is to blame. I don't know why, it's just a hunch...



My Answer:
't have a specific file extension, but they are typically saved with a .twig extension for clarity and organization. However, you can also use .html or .php extensions for Twig templates if you prefer.

Rate this post

3 of 5 based on 4490 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us