doupin5667 2016-08-02 00:07
浏览 33

枝条支持孙子继承吗?

My web application is structured as follows:

  • master.html (contains the master layout for the page)
  • page.html (contains the content of an individual page)
  • child.html (contains some data that may or may not be loaded)

I've got javascript in the child.html that needs to go beneath my jQuery link in master.html. Does Twig have a tag such that this is possible?


Clarifying with an example of sample output:

<!DOCTYPE html>
<html>
    <head>
    ...
    </head>
    <body>
        <!-- Content of page.html, which has content from child.html within it -->

        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <!-- Scripts from child.html -->
    </body>
</html>
  • 写回答

2条回答 默认 最新

  • doulu4203 2016-08-02 05:49
    关注

    You create blocks in the master.html template and you can override these in page.html, as in child.html

    master.html

    <!DOCTYPE html>
    <html>
        <head>
            <title>{{ title | default('Hello World') }}</title>
            <link rel="stylesheet" type="text/css" href="theme.css">
            {% block css %}
            {% endblock %}
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
            {% block javascript_sources %}
            {% endblock %}
        </head>
        <body>
            <script>
               //default code
            </script>
        </body>
    </html>
    

    page.html

    {% extends "master.html" %}
    {% block javascript_sources %}
        <script src="my.jquery.plugin.min.js"></script>
    {% endblock %}
    {% block javascript %}
         <script>
             $(function(){
                console.log('-- page loaded --');
             });
         </script>
     {% endblock %}    
    

    child.html

    {% extends "page.html" %}
    {% block javascript %}
        {{ parent() }}
        <script>
            $(function(){
                console.log('-- child loaded --');
            });
        </script>
    {% endblock %}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了