Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

How do I add an if statement here:

Aloittaja Biology Forums, lokakuu 22, 2013, 07:56:48 IP

« edellinen - seuraava »

Biology Forums

$normal_buttons = array
(
'reply' => array('text' => 146, 'image' => 'reply.gif', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies']),
'new_topic' => array('text' => 'smf258', 'image' => 'new_topic.gif', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0'),


What like to add an if statement between the first ( and 'new_topic'. So:

$normal_buttons = array
(

if(SOMETHING)

'reply' => array('text' => 146, 'image' => 'reply.gif', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies']),

ELSE

'someotherreply' => array('text' => 146, 'image' => 'reply.gif', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies']),

'new_topic' => array('text' => 'smf258', 'image' => 'new_topic.gif', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0'),

All Colours Sam

You can add a single key on any already created array:

$normal_buttons['reply']

if (something)
$normal_buttons['reply'] = ....


else
$normal_buttons['reply'] = ....
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

Biology Forums

However,

$normal_buttons = array
(


Is quite large. I was hoping to add a small IF statement within the array.

Arantor

You can't add a statement inside another statement.

It would, as ever, help to know the context because I can think of at least three other ways this could be done and the best one relates to what you're trying to do.
Holder of controversial views, all of which my own.


Biology Forums

$normal_buttons = array
(
'reply' => array('text' => 146, 'image' => 'reply.gif', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies']),
'new_topic' => array('text' => 'smf258', 'image' => 'new_topic.gif', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0'),
'bookmark' => array('test' => 'can_make_bookmarks', 'text' => 'bookmark_add', 'lang' => true, 'url' => $scripturl . '?action=bookmarks;sa=add;topic=' . $context['current_topic']),
'notify' => array('test' => 'can_mark_notify', 'text' => $context['is_marked_notify'] ? 999 : 125, 'image' => $context['is_marked_notify'] ? 'unnotify.gif' : 'notify.gif', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_topic'] : $txt['notification_enable_topic']) . '\');"', 'url' => $scripturl . '?action=notify;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id']),
'custom' => array(),
'send' => array('test' => 'can_send_topic', 'text' => 707, 'image' => 'sendtopic.gif', 'lang' => true, 'url' => $scripturl . '?action=sendtopic;topic=' . $context['current_topic'] . '.0'),
'print' => array('text' => 465, 'image' => 'print.gif', 'lang' => true, 'custom' => 'target="_blank"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
);


There is the array...

I want to add, IF($CONTEXT['can_reply']) show 'reply' => array('text' => 146, 'image' => 'reply.gif', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies']), if not, show nothing.

Arantor

So, only show the reply button if a user can reply, yes?
Holder of controversial views, all of which my own.



Arantor

That's rather ironic, you're putting SMF 1.1.x back to how SMF 1.1.x ships.

There is already a mechanism in the button system for doing just that. Replace that one line with:

'reply' => array('test' => 'can_reply', 'text' => 146, 'image' => 'reply.gif', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies']),

The 'test' parameter checks the matching $context variable, in this case $context['can_reply'].

But THIS is why I asked why, so that the best option can be done.
Holder of controversial views, all of which my own.


Biology Forums

Lainaus käyttäjältä: Arantor - lokakuu 22, 2013, 08:11:59 IP
That's rather ironic, you're putting SMF 1.1.x back to how SMF 1.1.x ships.

There is already a mechanism in the button system for doing just that. Replace that one line with:

'reply' => array('test' => 'can_reply', 'text' => 146, 'image' => 'reply.gif', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies']),

The 'test' parameter checks the matching $context variable, in this case $context['can_reply'].

But THIS is why I asked why, so that the best option can be done.

Very true, I was wondering what TEST meant... Thank you, Arantor.

Advertisement: