Page 1 of 1

Help with some code needed!

Posted: Wed Mar 12, 2008 1:42 am
by trumpy81
GDay All,

Would someone be so kind and step me through the following piece of code:

Code: Select all

if($easygbConfig_show_homepage && (!empty($row->homepage))) {
			  $tmpl->setAttribute('show_homepage', 'visibility', 'visible');
			  $tmpl->addVar('show_homepage', 'HOMEPAGE', (substr($row->homepage, 0, 4) != 'http' ? 'http://' . $row->homepage : $row->homepage));
			  $tmpl->addVar('show_homepage', 'EASYGB_VISIT_WEBSITE', EASYGB_VISIT_WEBSITE);
			}
I am getting lost as to what this piece of code is doing.

As I read it, it first checks for an empty entry, then if the entry is NOT empty, sets the 'visibility' attribute and adds a variable and then displays the entry.

This is where I get lost though:

Code: Select all

$tmpl->addVar('show_homepage', 'HOMEPAGE', (substr($row->homepage, 0, 4) != 'http' ? 'http://' . $row->homepage : $row->homepage));
Exactly what is happening in this line? In particular, what does the ? mean in this context.

Any help would be greatly appreciated.

Re: Help with some code needed!

Posted: Wed Mar 12, 2008 2:38 am
by Bodom78
The ? is like an "if statement"

Code: Select all

(substr($row->homepage, 0, 4) != 'http' ? 'http://' . $row->homepage : $row->homepage)
is the same as

Code: Select all

if(substr($row->homepage, 0, 4) != 'http')
{
     'http://' . $row->homepage;
}
else
{
     $row->homepage;
}

Re: Help with some code needed!

Posted: Wed Mar 12, 2008 3:11 am
by trumpy81
GDay All,

Bodom78, Thanks heaps!. :D That really helps in my understanding of this particular component.