Help with template

Hello,

I declared two variables sidebar1 and sidebar2

I am getting undefined.

How do I fill these from my controller and pass the data?

Thanks in advance.




<?php $this->beginContent('//layouts/main'); ?>

<div class="container">

	<div class="span-4">

		<p>

			<h2>Sidebar 1</h2>

			<?php echo $sidebar1; ?>

		</p>

	</div>

	<div id="content" class="span-14">

		<?php echo $content; ?>

	</div><!-- content -->

	<div class="span-4">

		<p>

			<h2>Sidebar 2</h2>

			<?php echo $sidebar2; ?>

		</p>

	</div>

</div>

<?php $this->endContent(); ?>



Surely there are many ways to approach your problem. I would pick either of the following:

if $sidebar1 is just a variable I would declare it first and then print it:


<p>

                        <h2>Sidebar 1</h2>

                        <?php $sidebar1='Some text'; ?>

                        <?php echo $sidebar1; ?>

                </p>

but I suspect that this is not what you are trying to achive as it does not make much sense to declare it and print it when you can just print it.

What I would do is render a widget such as


<?php $this->widget('application.components.someWidget'); ?>

and declare and render as many variables as you want in that widget

http://www.yiiframework.com/doc/guide/1.1/en/basics.view#widget

Thanks,

I wanted to load it in the controller and have it render.

I’ll look into using a widget, but I still would want to load data in the controller, because it can change depending on current page viewed.

Hi how can I add some column or sidebar to my yii2 template ?