News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Adding 'target' => '_blank', to an array

Started by Steve, January 30, 2015, 05:38:31 PM

Previous topic - Next topic

Steve

If I have this snippet of code:

            'custom1' => array(
                'title' => !empty ($modSettings['label_custombuttons_1']) ? $modSettings['label_custombuttons_1'] : $txt['cb_default_1'],
                'href' => !empty ($modSettings['url_custombuttons_1']) ? $modSettings['url_custombuttons_1'] : $scripturl,
                'show' => $context['allow_custom_button1'] && !empty ($modSettings['enable_custombuttons_1']) ? true : false,


And I want the button this is for to open in a new tab or window, is this correct?

            'custom1' => array(
                'title' => !empty ($modSettings['label_custombuttons_1']) ? $modSettings['label_custombuttons_1'] : $txt['cb_default_1'],
                'href' => !empty ($modSettings['url_custombuttons_1']) ? $modSettings['url_custombuttons_1'] : $scripturl,
'target' => '_blank',
                'show' => $context['allow_custom_button1'] && !empty ($modSettings['enable_custombuttons_1']) ? true : false,
DO NOT pm me for support!

Shambles


Steve

I did and it works. I guess I should have stated that. What I wanted to know, is it correct coding? e.g. Should the target line be on a separate line or the same line as the one before it, or does it not matter? :)
DO NOT pm me for support!

Arantor

In an array definition, whether you use the same line or the next line for items doesn't matter.

These are functionally identical:

$var = array('thing' => 'My Thing', 'thing2' => 'My Other Thing');



$var = array(
    'thing' => 'My Thing',
    'thing2' => 'My Other Thing',
);


Just for the big-ass arrays like the menu, one entry per line is simply easier to read.

Steve

That's what I needed to know. Thanks as always. And you're still a gentleman and a scholar. :P
DO NOT pm me for support!

Advertisement: