Help with some code needed! Topic is solved

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
trumpy81

Help with some code needed!

Post by trumpy81 » Wed Mar 12, 2008 1:42 am

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.

Bodom78
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Fri Nov 04, 2005 9:23 am

Re: Help with some code needed!

Post by Bodom78 » Wed Mar 12, 2008 2:38 am

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;
}

trumpy81

Re: Help with some code needed!

Post by trumpy81 » Wed Mar 12, 2008 3:11 am

GDay All,

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


Post Reply