Conditional Layouts

Hi dears,

While on working on my current project Using Yii, I have some sort of problem while implementing the layouts for the specific actions.

I want to display different side menus based on the actions.

The Problem is that

When I pass data to the page using


$this->render('page',array('menu'=>$menu));

and access it on the layout page as




if(!empty($menu)){

// show side menu

}else{

//Page without side menu

}



But it is not working

I have done it using layout. But How to do it with a single page layout?

Any Suggestion will be welcomed.

Thanks

Hi Pero,

Have you check the default layouts of Yii? Look how $pageTitle and $breadCrumbs are set from action Views and you have the solution to your problem :).

Look under your components folder for the Controller class (this is where your Controller extends from), in there you will see a set of variables, include one more and called $sideMenu or $menu or whatever. Then on your controllers action view set or not the variable as:

on your action

$this->render(‘page’,array(‘menu’=>$menu));

on your view

$this->sideMenu = $menu; or $this->sideMenu = false; or whatever your criteria is.

On your main layout:

if (false !== $this->sideMenu ) or whatever

show menu

I know you already know how to continue

Cheers!

Hi Antonio,

Thanks for your help.

A pleasure

edit: saying a pleasure gives me a -1 votes? :) Well, thanks, I would love to know why but I guess it comes with the culture of everyone. My parents always told me to be grateful for people’s help and also to respond with humbleness to people’s gratitude. Maybe I should not spend so much time in the forum.

People Who help others and Forget it and never seeks for reward, then there is a big reward ready for them.

If someone helps others in a soft manner either its help is fruitful for others or not, is far batter then a person who helps in rude manner either it completely resolves the issue.

  • Vote or + Vote does not matter. But Still a +Vote is of great importance.

Thanks

PeRoChAk:

Did you down vote Antonio?

If you did: why?

why do you need -vote? why not +vote?

Hi Pero, since I got to know Yii I have been ‘hooked’ not only by its framework but also about the great community it has. Since I learn from others I dedicate most of my free time to ‘spread’ the know how as others did for me in the past. I really do not care about -Vote or +Vote, the most important thing for me is to help as by helping I also help my self in the search of the best solutions. I am not rude whatsoever and if I have been I apologize for those who felt that way as I tend to ‘work together in the search of a solution’ with others. In fact, I even write wiki articles, create extensions for others, and most of my blog articles are now fully dedicated to Yii and I do not ask for anything at all in return, I just wish that my small input can help this community grow.

But, if someone says thank you, I say that is a pleasure to help. I didn’t care for the -Vote (see my :)?) I just thought it was rude to do that when somebody is trying to help with its free time somebody else and for no reason at all, because somebody said: ‘a pleasure?’. Nevertheless, why a +Vote is of great importance? do I make money with it? do anybody in this network does?

I think I am talking far too much in a matter that only relates to ethics than programming.

Anyway, cheers

You are being an ass.

Plain and simple.

Maybe a polite ass, but an ass none the less.

Antonio is in the upper ten percent of helpful Yii community people.

What’s in it for him?

What’s in it for you?

The only thing you did now was make Antonio sad - and (hopefully) people will learn that they gain nothing from helping you.

Dear Antonio,

Is it not just a joke that People think that everything is money or materialistic?

Dear jacmoe,

I will not say anything about what you said but I would like to answer your questions

There is a lot. For example, Experience, Inner Joy, Sanctification and a lot of others that can’t be bought.

If someone did not wants to be happy if some one says that Its a great by him to help him out from trouble then I can’t say anything.

I know that there is nothing for others but I think there is a lot of others too.

If someone asks a Question in true manner then I think this is something that one wants from others.

If you know something and your knowledge does not help others then it’s waste and nothing more then it.

I would like to ask just one Question

People spent their valuable in writing scripts and then give it to others and they know that there is nothing but just Thanks for them from 99% of the users of the product that they give.

Why People do that?

Hopefully, My words will not hurt anyone.

Pero,

Forget everything. I believe it is a big culture misunderstanding. Lets leave this ethical questions. If you read my texts you will realize that I do not care about anything; if I helped you i am happy. Thats all.

Cheers

Dear Antonio,

Thanks dear.

I have already forget.

Thanks for your help and guideline.

Pero: You have my respect.

A forum, even with smilies, is a very limited (and dangerous sometimes…) format for communication.

Especially when people from different cultures meet.

It’s amazing that we actually do manage to make conversations. ;)

Dear jacmoe,

It’s valuable for me.

Cultures are made by the insights of people. Hopefully, there is one part of the body that still feel something smiler for all, the sympathetic, love and respect( for innocents of any culture)

Thanks you all.