简体   繁体   中英

Why controller not render twig template

I have a template ( homepage.html.twig ) in app/Resources/homepage . I'm trying to render this template within the HomeController class.


namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class HomeController extends Controller
{
    /**
     * @Route("/home", name="homepage")
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function homeAction()
    {
        return $this->render('homepage/homepage.html.twig');
    }
}

This is the content of the template.

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

{% block body %}
    <div class="container">
        <div class="jumbotron">
            <h1>Navbar example</h1>
            <p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
            <p>
                <a class="btn btn-lg btn-primary" href=# role="button">View navbar docs &raquo;</a>
            </p>
        </div>
    </div>
{% endblock %}

Why doesn't rendering the template work?

I fixed the problem by putting

{% block body %}
{% endblock %}

in the base.html.twig

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM