简体   繁体   English

树枝模板扩展

[英]Twig templates extending

I'm trying to set up a page layout with separate common header and footer, extending from twig templates. 我正在尝试从细枝模板扩展到具有单独的公共页眉和页脚的页面布局。

Page layout it's a tipycal one with some code like this: 页面布局是一个简单的页面,其中包含如下代码:

<!doctype html>
<html class="no-js" lang="zxx">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Soccer | Home</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="apple-touch-icon" href="apple-touch-icon.png">
    <!-- Place favicon.ico in the root directory -->
    <link rel="shortcut icon" type="image/x-icon" href="{{ asset('assets/images/fav.png') }}">

    <!-- CSS BLOCK -->
    {% stylesheets 'assets/css/*' 'assets/css/style.css' filter='cssrewrite' %}
        <link rel="stylesheet" href="{{ asset_url }}"/>
    {% endstylesheets %}
</head>
<body class="home-two">

    {% block page_layout_header %} {% endblock %}

    {% block content %} {% endblock %}

    {% block page_layout_footer %} {% endblock %}

    <!-- JS BLOCK -->
    {% javascripts 'assets/js/jquery.min.js'
        'assets/js/rsmenu-main.js'
        'assets/js/jquery-ui.min.js'
        'assets/js/bootstrap.min.js'
        'assets/js/jquery.meanmenu.js'
        'assets/js/wow.min.js'
        'assets/js/slick.min.js'
        'assets/js/masonry.js'
        'assets/js/owl.carousel.min.js'
        'assets/js/time-circle.js'
        'assets/js/jquery.magnific-popup.js'
        'assets/js/main.js' %}
            <script src="{{ asset_url }}"></script>
    {% endjavascripts %}

</body>
</html>

I've got another file under ( app\\Resources\\views\\parts\\page_layout_header.html.twig ) where I've setted a part of the website, extending from pagelayout.html.twig . 我在( app\\Resources\\views\\parts\\page_layout_header.html.twig )下有另一个文件,该文件设置了网站的一部分,从pagelayout.html.twig扩展。

Finally, root_folder it's under full/home.html.twig and it renders a simple template like this: 最后,root_folder位于full/home.html.twig ,并呈现一个简单的模板,如下所示:

{% extends "pagelayout.html.twig" %}
{% block content %}
    <h1>Root page</h1>
{% endblock %}

In the ezplatform.yml I've setted the root folder and a line for the header twig. ezplatform.yml我设置了根文件夹和标头细枝的一行。

content_view:
    full:
        root_folder:
            template: "full/home.html.twig"
            match:
                Id\Location: 67
    line:
        line_part_header:
            template: "parts/page_layout_header.html.twig"
            match:
                Identifier\ContentType: ['defined_content_type']

The issue comes when launching 127.0.0.1:8000 root page and nothing appears to be rendered. 启动127.0.0.1:8000根页面时出现问题,并且似乎未呈现任何内容。 Only content from root ez folder is showing without any CSS Style. 仅显示根ez文件夹中的内容,而没有任何CSS样式。 It seems that extending from twig templates is not working... 似乎从树枝模板扩展不起作用...

EDIT: Gonna explain my situation better. 编辑:可以更好地解释我的情况。

This is partial of pagelayout.html.twig which has all css, js and block definitions 这是pagelayout.html.twig一部分,其中包含所有CSS,JS和块定义

{% stylesheets 'assets/css/*' 'assets/css/style.css' filter='cssrewrite' %}
    <link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}

{% block header %} {% endblock %}

{% block content %} {% endblock %}

{% block footer %} {% endblock %}


<!-- BLOQUE JS -->
{% javascripts 'assets/js/*' %}
    <script src="{{ asset_url }}"></script>
{% endblock %}

Next, I've got a page_layout_header.html.twig wich contains a top bar and the main menu. 接下来,我有一个page_layout_header.html.twig其中包含一个顶部栏和主菜单。

{% extends ':themes/club:pagelayout.html.twig' %}
{% block header %}
<!--Header area start here-->
<header>
    <div class="header-top-area">
        <div class="container">
            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                    <div class="header-top-left">
                        <ul>
                            <li><a href="mailto:#"><i class="fa fa-envelope-o" aria-hidden="true"></i> {{ ez_render_field( content, 'web_config_email_contacto' ) }}</a></li>
                            <li><img src="{{ asset('assets/images/logo/flag.jpg') }}" alt="Logo">
                            ......
                            ......

And finally, this is the config: 最后,这是配置:

home:
    template: "themes/club/full/home/home.html.twig"
    match:
        Id\Location: 2
full_top:
    template: "themes/club/parts/page_layout_header.html.twig"
    match:
        Identifier\ContentType: 'informacion_general'

So, when testing http://127.0.0.1 I cannot see anything more than {{ ez_render_field(content, 'description') }} 因此,在测试http://127.0.0.1时,除了{{ ez_render_field(content, 'description') }}以外,我什么都看不到

Extending templates means that child template extends parent template, but it doesn't mean parent template includes child one. 扩展模板意味着子模板扩展了父模板,但并不意味着父模板包括子模板。

So your both templates ( home.html.twig and page_layout_header.html.twig ) extend pagelayout.html.twig independently. 因此,您的两个模板( home.html.twigpage_layout_header.html.twig )都分别扩展了pagelayout.html.twig And they both don't know anything about each other. 他们俩对彼此一无所知。

I'm not familiar with EzPlatform but it looks like full and line view types are just different configurations to be chosen by ViewProvider or something like this. 我不熟悉EzPlatform,但看起来full视图和line视图类型只是ViewProvider或类似方法选择的不同配置。

So I decide you should embed reusable parts of html by simply including it like this: 因此,我决定您应该通过简单地包含如下内容来嵌入html的可重用部分:

{% include 'page_layout_header.html.twig' %}

https://twig.symfony.com/doc/2.x/tags/include.html https://twig.symfony.com/doc/2.x/tags/include.html

or by rendering it with separate controller like this: 或通过像这样的单独控制器渲染它:

{{ render(controller("ez_content:viewAction", {"contentId": 123, "viewType": "line"})) }}

https://doc.ezplatform.com/en/2.1/guide/content_rendering/#embedding-content-items https://doc.ezplatform.com/cn/2.1/guide/content_rendering/#embedding-content-items

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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