title: YII2 Putting Cycle in partial view and using it in layout – include vs render?
body: <p>I would like to use the sjaakp\cycle\Cycle::widget in my main layout in order to have a banner slideshow. 
  When putting the code directly into the main layout, it works pretty well. 
  But in order to make the layout more readable, I would like to put the code into a separate php file, says _banner-slide-show.php and use </p>
  
  <pre><code>&lt;?php $this-&gt;render('_banner-slide-show');?&gt;
  </code></pre>
  
  <p>but it doesn't work. The pages are visible but the banner slideshow doesn't appear and there is no trace of images in the source code of pages.</p>
  
  <p>If I use </p>
  
  <pre><code>&lt;?php include ('_banner-slide-show.php')
  </code></pre>
  
  <p>It works pretty well again. </p>
  
  <p>My question is why doesn't it work with render ?</p>
  
  <p>here is the code in _banner-slide-show.php</p>
  
  <pre><code>                 &lt;?php
               use yii\data\ArrayDataProvider;
               use yii\helpers\Url;
  
  
                  // $photos = scandir($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'banner', 1);
                      $photos = scandir($_SERVER['DOCUMENT_ROOT'] 
                              . DIRECTORY_SEPARATOR . '..'
                              . DIRECTORY_SEPARATOR . '..'.
                              '/images/admin/banner', 1);
                      $dataPhotos = array();
                      foreach ($photos as $photo) {
                         // array_push($dataPhotos, ['photo' =&gt; '@web/banner/' . $photo]);
                          $url=Url::to(['/image/view', 'filePath' =&gt; 'admin/banner/'.$photo]);
  array_push($dataPhotos,['photo' =&gt; $url]) ;
                      }
  
                      array_pop($dataPhotos);
                      array_pop($dataPhotos); //remove . and ..
  
  
                      $dataProv = new ArrayDataProvider(['allModels' =&gt; $dataPhotos,
                          'pagination' =&gt; false]);
                      ?&gt;
                      &lt;?=
                      sjaakp\cycle\Cycle::widget([
                          'dataProvider' =&gt; $dataProv,
                          'imgAttribute' =&gt; 'photo',
                          // 'captionAttributes' =&gt; ['photo'],
                          // 'overlayAttributes' =&gt;['photo'],
                          'options' =&gt; [
                              'captionPlugin' =&gt; 'caption2',
                              'captionFxOut' =&gt; 'slideUp',
                              'captionFxIn' =&gt; 'slideDown',
                              'allow-wrap' =&gt; false,
                              'auto-height' =&gt; 0,
                              'fx' =&gt; 'fadeOut',
                              'timeout' =&gt; 8000,
                              'speed' =&gt; 2000,
                          //    'overlay' =&gt; '#ovl'
                          ],
                      ])
                      ?&gt;
                      &lt;!-- &lt;div id="ovl" class="cycle-overlay"&gt;&lt;/div&gt; --&gt;
  </code></pre>