News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

Only show Print button if user is logged in (not for guests)

Started by spiros, March 06, 2025, 12:54:26 PM

Previous topic - Next topic

spiros

I want to have a conditional display of the print button only if user is logged, so I changed this:

// Build the normal button array.
.....
'print' => array('text' => 'print', 'image' => 'print.gif', 'lang' => true, 'custom' => 'rel="new_win nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
   );


Into this:

// Build the normal button array.
.....
if(
$context['user']['is_logged'])
{
   echo
'
'
print' => array('text' => 'print', 'image' => 'print.gif', 'lang' => true, 'custom' => 'rel="new_win nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
'
;
}
   );


But I get an error
Quotesyntax error, unexpected token "if", expecting ")"

Doug Heffernan

Quote from: spiros on March 06, 2025, 12:54:26 PMI want to have a conditional display of the print button only if user is logged, so I changed this:

// Build the normal button array.
.....
'print' => array('text' => 'print', 'image' => 'print.gif', 'lang' => true, 'custom' => 'rel="new_win nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
);


Into this:

// Build the normal button array.
.....
if(
$context['user']['is_logged'])
{
   echo
'
'
print' => array('text' => 'print', 'image' => 'print.gif', 'lang' => true, 'custom' => 'rel="new_win nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
'
;
}
);


But I get an error
Quotesyntax error, unexpected token "if", expecting ")"

The whole echo statement is the issue, not to mention the ending bracket with the semicolon which has been moved outside the if statement.

Kindred

look at the coloring on the parsed content.....

by adding the echo, you broke it.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

shawnb61

Note that if you are adding a conditional echo in the middle of an existing echo, you turned it into ***3*** different echos.

You have to ensure each echo command has proper opening & closing quotes and semicolons. 

E.g., if you're starting with a single echo that looks like this:
Quoteecho 'a<br>
    c<br>';

Inserting a conditional echo in the middle needs to become something more like:
Quoteecho 'a<br>';
if (xxxx)
{
    echo 'b<br>';
}
echo 'c<br>';
A question worth asking is born in experience & driven by necessity. - Fripp

spiros

Thank you a million guys, I tried different ways but still cannot figure out how to make it work, I would so appreciate it if someone could help.

GL700Wing

Quote from: spiros on March 07, 2025, 04:09:58 AMThank you a million guys, I tried different ways but still cannot figure out how to make it work, I would so appreciate it if someone could help.
Here ya go ...

In ./Themes/default/Display.template.php
Find:
        'print' => array('text' => 'print', 'image' => 'print.gif', 'lang' => true, 'custom' => 'rel="new_win nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
    );

Replace with:
    );

    if ($context['user']['is_logged'])
        $normal_buttons += array(
            'print' => array('text' => 'print', 'image' => 'print.gif', 'lang' => true, 'custom' => 'rel="new_win nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
        );
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

spiros


Advertisement: