htmlcsszend-framework2zend-form

Using css DIV areas in View Script


In my layout script I have some css areas, like:

<div id="section-navigation">
            Test
</div>

How can I override these sections in my view script with other data? I´d like to override it dynamically.

here is a snippet of my layout.phtml

<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headTitle(); ?>
<?php echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/grid.css'); ?>
</head>
<body>
<div id="container">
    <div id="header">
        <h1><img src="./Images/cheyenne.jpg" alt="cheyenne-IT consulting" width="490" height="115" /><?php echo $this->escape($this->title); ?></h1>
    </div>
    <div id="navigation">
        <ul>
                <li><a href="<?php echo $this->url(array('controller'=>'arbeitskalender', 'action'=>'index'));?>">Arbeitskalender</a></li>

        </ul>
    </div>
    <div id="content-container">
        <div id="section-navigation">
            test
        </div>

        <div id="aside">
            test
        </div>
        <div id="content">
            <?= $this->layout()->content ?>
        </div>

  </div>
  <div id="footer">
            copyright 2014  
    </div>
</div>
</body>

Probably there is another property in the form layout?

$this->layout()->content 

Solution

  • If the links you would have in the navigation <div> changes for every action and you want to set it dinamically, then you could create a custom view script file and render it in your layout.

    Something like this :

    navigation.phtml:

    <ul>
        <li><a href="<?php echo $this->link; ?>"><?php echo $this->name; ?></a></li>
    </ul>
    

    Then add it to the view_manager in your module.config:

    'view_manager' => array(
        'template_map' => array(
             //.....
            'navigation/view' => __DIR__ . '/../view/layout/navigation.phtml',
        ),
    

    In your action (controller) :

    $url = $this->url()->fromRoute('route-name',
                                    array('controller'=>'arbeitskalender', 
                                          'action'=>'index')
                                  );
    $navlinks = new ViewModel(
                    array(
                       'link'    => $url ,
                       'name'    => 'Arbeitskalender'
                    )
    );
    $navlinks ->setTemplate('navigation/view');
    $nav= $this->getServiceLocator()->get('Zend\View\Renderer\RendererInterface')
                                    ->render($navlinks);
    
    $viewLayout = new ViewModel(array('nav' => $nav));
    return $viewLayout;
    

    In your layout :

    <div id="section-navigation">
       <?php echo $this->nav; ?> 
    </div>
    

    You could also see the Partial Helper. Create a partial script like this:

    <?php // partial.phtml ?>
    <ul>
     <li><a href="<?php echo $this->link; ?>"><?php echo $this->name; ?></a></li>
    </ul>
    

    And then call it from your layout script using the following:

    <div id="section-navigation">
     <?php echo $this->partial('partial.phtml', array(
        'link' => $this->link,
        'name' => $this->name)); ?> 
    </div>