ZF2 Как использовать javascripts и таблицы стилей страниц в макете

Я использую зенд фреймворк 2.

Это мой layout.phtml

<?php echo $this->doctype(); ?>
<html class="fixed" lang="en">
<head>

    <!-- Basic -->
    <meta charset="UTF-8">
    <?php echo $this->headTitle('Test') ?>

    <?php

        /* Vendor CSS */
        $this->headLink(array(
                'rel' => 'shortcut icon',
                'type' => 'image/vnd.microsoft.icon',
                'href' => $this->basePath() . '/img/favicon.ico'
            ))
            ->appendStylesheet($this->basePath() . 'aaaa.css')
            ->appendStylesheet($this->basePath() . 'bbbb.css');


        /* Specific Page Vendor CSS */
        $this->headLink()
            ->appendStylesheet($this->basePath() . 'cccc.css')
            ->appendStylesheet($this->basePath() . 'dddd.css')

        /* Theme CSS */
        $this->headLink()
            ->appendStylesheet($this->basePath() . 'eeee.css');       
    ?>

</head>
<body>

<section class="body">

    <?php print $this->render('layout/header') ?>

    <div class="inner-wrapper">
        <?php print $this->render('layout/left-menu') ?>

        <section role="main" class="content-body">
            <?php echo $this->content; ?>
        </section>
    </div>

    <?php print $this->render('layout/right-menu') ?>
</section>

<?php
    /* Vendor */
    $this->headScript()
            ->appendFile($this->basePath() . 'aaaa.js')
            ->appendFile($this->basePath() . 'bbbb.js');          

    /* Specific Page Vendor */
    $this->headScript()
        ->appendFile($this->basePath() . 'cccc.js')
        ->appendFile($this->basePath() . 'dddd.js);

    /* Theme Base, Components and Settings */
    $this->headScript()
        ->appendFile($this->basePath() . 'eeee.js');

?>

</body>
</html>

Этот макет работает нормально. Но в layout.phtml нет необходимости задавать конкретных поставщиков страниц. Он будет меняться вместе с контентом. Поэтому мне нужно переместить часть /* конкретного поставщика страниц */ в соответствующий файл .phtml. После этого мой макет и содержимое должны быть такими.

layout.phtml тип документа(); ?>

    <!-- Basic -->
    <meta charset="UTF-8">
    <?php echo $this->headTitle('Test') ?>

    <?php

        /* Vendor CSS */
        $this->headLink(array(
                'rel' => 'shortcut icon',
                'type' => 'image/vnd.microsoft.icon',
                'href' => $this->basePath() . '/img/favicon.ico'
            ))
            ->appendStylesheet($this->basePath() . 'aaaa.css')
            ->appendStylesheet($this->basePath() . 'bbbb.css');

        /* Theme CSS */
        $this->headLink()
            ->appendStylesheet($this->basePath() . 'eeee.css');       
    ?>

</head>
<body>

<section class="body">

    <?php print $this->render('layout/header') ?>

    <div class="inner-wrapper">
        <?php print $this->render('layout/left-menu') ?>

        <section role="main" class="content-body">
            <?php echo $this->content; ?>
        </section>
    </div>

    <?php print $this->render('layout/right-menu') ?>
</section>

<?php
    /* Vendor */
    $this->headScript()
            ->appendFile($this->basePath() . 'aaaa.js')
            ->appendFile($this->basePath() . 'bbbb.js');  

    /* Theme Base, Components and Settings */
    $this->headScript()
        ->appendFile($this->basePath() . 'eeee.js');

?>

</body>
</html>

Контент.phtml

/* Specific Page Vendor CSS */
$this->headLink()
    ->appendStylesheet($this->basePath() . 'cccc.css')
    ->appendStylesheet($this->basePath() . 'dddd.css')

<h1>This is content of the page</h1>

/* Specific Page Vendor */
$this->headScript()
    ->appendFile($this->basePath() . 'cccc.js')
    ->appendFile($this->basePath() . 'dddd.js);

Предположим, что нижние таблицы стилей переопределяют таблицы стилей выше. нижний javascript использует вышеуказанные функции javascript.

Как мне это сделать?


person Dinuka Thilanga    schedule 22.10.2014    source источник
comment
Какие? а почему дублируется?   -  person NDM    schedule 22.10.2014
comment
Не очень понятно, в чем дело. Вы говорите, что вам нужно переместить некоторые из ваших заголовков в соответствующий файл .phtml - вы пробовали это? Он должен работать нормально.   -  person Tim Fountain    schedule 22.10.2014
comment
Вы хотите использовать разные макеты для разных страниц?   -  person Next Developer    schedule 23.10.2014


Ответы (1)


Файлы макета и файлы страниц следует хранить отдельно. Макет JS/CSS — это файлы, которые нужны вам на КАЖДОЙ странице.

Файлы стиля содержимого / javascript всегда загружаются из действий контроллера.

$api->getView()->inlineScript()->appendScript('assets/js/jsfile.js');
$api->getView()->headLink()->appendStylesheet('assets/css/cssfile.css')
person poashoas    schedule 24.10.2014
comment
мне нужно добавить cccc.js, dddd.js в bbbb.js и eeee.js. это не добавление. - person Dinuka Thilanga; 24.10.2014