Show a block only on homepage

Permalink
Can someone tell me how i can show some content ONLY on the homepage?

Like a "if else" function:

if () {
Content Block
} else {
No Content Block
}

Thanks in advance!

 
Mnkras replied on at Permalink Reply
Mnkras
$pageType = CollectionType::getByHandle(home)

so do if $pagetype = home

//code

else

//code

or just make a pagetype specifically for the homepage
jgarcia replied on at Permalink Reply
jgarcia
Couldn't you just add the block only to the homepage?
Robert2010 replied on at Permalink Reply
No because its in the footer element..

I could just include another footer, but i was looking for a better way.

So i will try the reply of Mnkras.

Will let you all know if this works for the footer include works.
Robert2010 replied on at Permalink Reply
Does'nt work in the footer element.

Does anyone have another suggestion?
Mnkras replied on at Permalink Reply
Mnkras
make a pagetype for the home page

and something like
$page = $pageType->getCollectionTypeHandle()
if( $page == home )
//code
else
//code


didn't work?
hursey013 replied on at Permalink Best Answer Reply
hursey013
This is what I always use, assuming the cID of your homepage hasn't changed:
if ($c->getCollectionID() == 1) { CODE GOES HERE }
Fernandos replied on at Permalink Reply
Fernandos
thanks for sharing this :)

I've another maybe more comfortable and userfriendly method of doing this.

I'm using page attributes.
Mostly boolean types, because they're easier for cients.

Little example: add a boolean page attribute
Add that attribut to your specific page and check it. It's so easy, just uncheck it to disable it.
<?php
if($c->getCollectionAttributeValue('my_attribute') == 1) {
      echo '<script type="text/javascript" src="'. $this->getThemePath().'/js/myscript.js"></script>';
     }

^^ I know I could use the htmlHelper.. but well it's not as powerfull as I wished it was. Meaning it doesnt support defer attributes in script and charset and many other attributes of the <link tag too. This could be implemented really easily, I would do that, but I'm not that familiar with custom function parameter amounts. I don't know howto create a function without ending with a function call like this: $html->example('defer',1,'xy',3,null,'hello',null,null,null);
The nulls^ are annoying..

This way I avoid having too many page_types.
Robert2010 replied on at Permalink Reply
Thanks hursey013, that worked for me :)

How does that cID work?

If the about page is on the second place in the sitemap then cID == 2 ?
Mnkras replied on at Permalink Reply
Mnkras
nope its in the order the pages were created
Robert2010 replied on at Permalink Reply
Were can i see what the cID # is?
jgarcia replied on at Permalink Reply
jgarcia
If you go to a page from the Site Map (from the Dashboard), you will see it in the URL in the form ofhttp://www.example.com/?cID=X, where X is the cID.