Symfony Error: “An exception has been thrown during the rendering of a template”

大憨熊 提交于 2019-11-30 19:14:13
Sarath Kumar

Execute the below commands:

yarn add --dev @symfony/webpack-encore

yarn add webpack-notifier --dev

yarn encore dev

It will generate the manifest.json file

I have resolved this problem by not using json_manifest_path: ~

comment out the json_manifest_path by adding '#' in front of it and add '~' after 'assets:'

framework:
    assets: ~
        #json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
nadjib chiheb

yarn encore dev-server --hot creates the manifest.json file

Try install Assets Bundle:

composer require symfony/asset

manifest.json is new in Symfony 3.3.

So, you should have this lines in your config file :

# app/config/config.yml
framework:
    # ...
    assets:
        json_manifest_path: '%kernel.root_dir%/../web/build/manifest.json'

If manifest.json isn't exists, you should create it, like this :

{ "css/app.css": "build/css/mystyle.b916426ea1d10021f3f17ce8031f93c2.css", "...": "..." }

Remember that the question is tagged Symfony4!

I have the same issue to add logo in navbar, favicon…

In Symfony4, there are no more app directory, so no app/config/config.yml ! In Symfony4, web directory doesn't exist anymore but there are new directory public

As @Bijaya wrote, just specify href or src address in public

In my case, I have my logo: myProjectName/public/logo_mom.png

and in my controller, I have:

/**
 * @Route("/", name="home")
 */
public function home() {
    return $this->render('blog/home.html.twig', [
        'title' => "Bienvenue",
        'logo_path' => "logo_mom.png",
        'logo_alt' => "logo alt description",
    ]);
}

and in my home.html.twig:

{% block body %}
    <h1>{{ title }}</h1>
    <img src={{ logo_path }} alt={{ logo_alt}}>

and in my template/base.html.twig:

<link rel="icon" type="image/x-icon" href="favicon.ico" />

So for me who discover Symfony4 without previous Symfony version knowledge, it is nice that doesn't required asset function or any other configuration!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!