What does this mean?

Permalink
Hey,

I've been poking around is some various code examples (in this case, Jordan Lev's Page List Teaser) and have come across a code syntax that I don't understand.

Can someone tell me what this means:
$target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');


You know... explain it to me like I'm stupid ('cuz I am, LOL!): This sets the variable "$target" to... now you fill-in the blanks. :D I'm guessing it's a short-hand means of writing an if-then statement... but I'm getting confused somewhere in there.

Thanks!

- John

arrestingdevelopment
 
mesuva replied on at Permalink Best Answer Reply
mesuva
Yes, this is a short hand if statement.

I would read it like this:
"if the page's link is not blank AND the page is set to open in a new window, set $target to be the string '_blank', otherwise set it to be the string stored in the page attribute called 'nav_target' "

See here for the 'ternary' operator
http://davidwalsh.name/php-shorthand-if-else-ternary-operators...

They're often critised for making things harder to read, but for simpler cases like this one, I think they are appropriate.
arrestingdevelopment replied on at Permalink Reply
arrestingdevelopment
Thanks, Mesuva.

The link to David Walsh's explanation really cleared it up, too! It was the "?" and ":" operators that were confusing me... I wasn't sure what they meant!

Appreciate the help!

- John