Page 1 of 1
PHP conditional based on page/section other than 'frontpage'
Posted: Thu Oct 25, 2007 11:13 pm
by lexpresso
I've figured out how to create conditional for content to appear based on whether the user is on the 'frontpage' or not, but how do you do it for any other page.
For example:
I want my 'main content' component to appear in one div on the frontpage, yet on another when I click on the "articles" link. This in order to achieve different widths for each. Are the names of the other "pages" custom...in otherwords can refer to them with the section name?

Re: PHP conditional based on page/section other than 'frontpage'
Posted: Fri Oct 26, 2007 3:13 am
by Opie
You could use two separate templates.
Also, if you know if the visitor is on the front page, can you not reverse that check to determine when you are not on the front page?
Re: PHP conditional based on page/section other than 'frontpage'
Posted: Fri Oct 26, 2007 3:18 am
by lexpresso
Yes I can, but I can't distinguish between various secondary pages:
Example:
if page==blog...or could be if section==blog {show this}
Is that clearer?

Re: PHP conditional based on page/section other than 'frontpage'
Posted: Sat Oct 27, 2007 3:10 am
by AmyStephen
You can look at the global variable $Itemid, a value associated with the menu item (it can be seen on the menu item line.)
Typically, it's a good idea to layout your menu item pages in a grid, then consider where all of your modules and component will go. Frequently, that knowledge is all that is needed to conditionally hide or show modules in the template.
Rarely do template designers create an entire template page for each menu item. But, if you do, then you should consider using the Template Manager to assign your various looks to the menu items. That way, you can keep the index.php files simpler.
Hope that helps!
Amy

Re: PHP conditional based on page/section other than 'frontpage'
Posted: Sat Oct 27, 2007 5:10 am
by lexpresso
Thanks. That should work.
Can you also refer to the id on in php conditional just as much as you can refer to the view?
Re: PHP conditional based on page/section other than 'frontpage'
Posted: Sat Oct 27, 2007 7:38 pm
by AmyStephen
lexpresso wrote:Can you also refer to the id on in php conditional just as much as you can refer to the view?
Yes, you certainly can! Here's an example:
Code: Select all
<?php If ($Itemid == 23) { ?>
do something
<?php } ?>
Good luck with your work,
Amy
