Render vs include in a layout


I want to use a sjaakp\cycle\Cycle widget for a banner slideshow. When I put my code directly in a div in the main.php layout, it works pretty fine.

But when I put the code into a partial view e.g. _banner-slideshow.php placed in the same directory than the main layout, and use the following in the layout

<?php $this->render('_banner-slideshow'); ?>

it doesn’t work and looking at the source code of the page I cannot see anything in the div where the render statement is placed.

Eventually using

<?php include ('_banner-slideshow.php'); ?>

it works fine also.

I have 2 questions:

1- How comes the render doesn’t work ?

2- What is the difference between including and rendering and does it matter to use render rather than include ?

PS: _banner-slideshow.php attached.

Try with echo:

<?php echo $this->render('_banner-slideshow'); ?>


<?= $this->render('_banner-slideshow'); ?>

IIRC, ‘render’ returns a string. So, do what Patrick suggests. :)

Many thanks

Both are working.