How to make an custom button the active one when clicked and...

Started by NanoSector, November 26, 2010, 04:02:54 PM

Previous topic - Next topic

NanoSector

Hello..

How do you make the clicked custom button the active one, and add something to the linktree?

I'm annoying myself that my users cannot click on the linktree to go back and they cannot see in which section they are...

Version: 2.0 RC4
Mods: None of your business (;))
Themes: Default
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

kat

Not sure I follow you, Yoshi.

With SMF v1.x, though, the XBox theme does that, I believe. Assuming I've understood what you mean, that is.

Might be worth looking at the code they use, in that.

Antechinus

How are you adding this custom button? What is it linking to?

Kays

On that page, you need to define $context['current_action'] to be the same as the name of that tab.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

NanoSector

Quote from: K@ on November 26, 2010, 04:26:12 PM
Not sure I follow you, Yoshi.

With SMF v1.x, though, the XBox theme does that, I believe. Assuming I've understood what you mean, that is.

Might be worth looking at the code they use, in that.
I mean like when the Members button is clicked it becomes "yellow". I want that.
The button also adds something to the linktree, I want that too (:P).

Quote from: Antechinus on November 26, 2010, 04:32:44 PM
How are you adding this custom button? What is it linking to?
'docs' => array(
'title' => $txt['docs'],
'href' => $docsurl, (it is the same as $boardurl . '/docs')
'show' => true,
),

Like that.

Quote from: Kays on November 26, 2010, 04:36:25 PM
On that page, you need to define $context['current_action'] to be the same as the name of that tab.
I might try that. Do you know any code that can do that (I'm no PHP expert you see ;))?
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Kays

Since you now have posted the code for the button. On the "docs" page add:


$context['current_action'] = 'docs';

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

NanoSector

Quote from: Kays on November 26, 2010, 04:40:30 PM
Since you now have posted the code for the button. On the "docs" page add:


$context['current_action'] = 'docs';

Allright. I will add the code right after calling SSI.php.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

NanoSector

Didn't work at all...no errors.

It still jumps to the Home button....
Maybe I need to global the "Context" variable?
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Antechinus

You also have to add the custom action to the array in index.php:

// Here's the monstrous $_REQUEST['action'] array - $_REQUEST['action'] => array($file, $function).
$actionArray = array(
'activate' => array('Register.php', 'Activate'),
'admin' => array('Admin.php', 'AdminMain'),
'announce' => array('Post.php', 'AnnounceTopic'),
'attachapprove' => array('ManageAttachments.php', 'ApproveAttach'),

NanoSector

Quote from: Antechinus on November 26, 2010, 04:53:00 PM
You also have to add the custom action to the array in index.php:

// Here's the monstrous $_REQUEST['action'] array - $_REQUEST['action'] => array($file, $function).
$actionArray = array(
'activate' => array('Register.php', 'Activate'),
'admin' => array('Admin.php', 'AdminMain'),
'announce' => array('Post.php', 'AnnounceTopic'),
'attachapprove' => array('ManageAttachments.php', 'ApproveAttach'),

...that's gonna work if I have my files in a "docs" directory in my forum directory?
I'm sorry but I really need directions...I'm a supernoob at these things :-[
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Kays

Quote from: Yoshi2889 on November 26, 2010, 04:47:12 PM
Didn't work at all...no errors.

It still jumps to the Home button....
Maybe I need to global the "Context" variable?

Yes, you could try globalising it.

In Subs.php this is what sets it up

Quote
   // Figure out which action we are doing so we can set the active tab.
   // Default to home.
   $current_action = 'home';

   if (isset($context['menu_buttons'][$context['current_action']]))
      $current_action = $context['current_action'];

   elseif ($context['current_action'] == 'search2')
      $current_action = 'search';
[/quote

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

NanoSector

...I tried globalling it but it didn't work at all.

here's the code in the file I'm modifying:

<?php

$ssi_gzip
= true;
$ssi_ban = true;  
ob_start();
require(
'/home/a9406461/public_html/forums/en/SSI.php');
require(
'/home/a9406461/public_html/forums/en/Settings.php');
global
$docsurl, $scripturl, $context;
$context['current_action'] = 'docs';
if(isset(
$context['page_title_html_safe']))
{
$context['page_title_html_safe'] = 'Documentation: Index';
} else {
$context['page_title'] = 'Documentation: Index';
}

   
// SMF header section coded for both versions 1.1.x and 2.0
   
if(!function_exists('template_header'))
   {
   
template_main_above();
   }  else {
     
template_header();
   }

//Content Section
   
if(!function_exists('template_header'))
   {

   echo
'';

   }  else {

   
// If SMF 2.x, place content here.

   
echo'
        <span class="clear upperframe"><span></span></span>
        <div class="roundframe"><div class="innerframe">'
;
        echo
'
        <div class="cat_bar">
        <h3 class="catbg">Documentation</h3>
        </div>
<p><a href="'
, $docsurl, '/Addons.php" title="Documentation: Addons">Addons</a><br>
<a href="'
, $docsurl, '/Autoconfig.php" title="Documentation: Autoconfig">Autoconfig</a><br>
<a href="'
, $docsurl, '/InstallingSMF.php" title="Documentation: Installing your SMF installation into SMFTools">Installing your SMF installation into SMFTools</a><br>
<a href="'
, $docsurl, '/SMFShell.php" title="Documentation: SMFShell">SMFShell</a></p><br><br>

<center><a href="'
, $scripturl, '">[Go back]</a></center>';
        echo
'
        </div></div>
       <span class="lowerframe"><span></span></span>'
;    

   }


 
// SMF footer section coded for both versions 1.1.x and 2.0
   
if(!function_exists('template_footer'))
   {
   
template_main_below(); // SMF 1.1.x header section
   
}  else {
     
template_footer();  //SMF 2.x header section
   
}

?>


Maybe you could do something with it...
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Kays

That page looks ok to me. Except you don't need to include Settings.php as SSI.php does that already.

You're trying to make to menu button appear active, correct? Just want to make sure.

What I posted is the start of a series of elseif statements. Add the following to the end of it


elseif ($context['current_action'] == 'docs')
$current_action = 'docs';



If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

NanoSector

Quote from: Kays on November 26, 2010, 05:21:16 PM
That page looks ok to me. Except you don't need to include Settings.php as SSI.php does that already.

You're trying to make to menu button appear active, correct? Just want to make sure.

What I posted is the start of a series of elseif statements. Add the following to the end of it


elseif ($context['current_action'] == 'docs')
$current_action = 'docs';

I need Settings.php to declare the $docsurl variable, else my documentation pages are...well...broken.
I will try that.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

NanoSector

My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

reversemortgage

Quote from: Yoshi2889 on November 26, 2010, 04:02:54 PM
Hello..

How do you make the clicked custom button the active one, and add something to the linktree?

I'm annoying myself that my users cannot click on the linktree to go back and they cannot see in which section they are...

Version: 2.0 RC4
Mods: None of your business (;))
Themes: Default


Hmm, I did a dsm($content) in my implementation, and $content['menu'] is a nested array with a bunch of numeric keys. I don't see a $content['links'], as suggested in the documentation.

What is the best way to work with the $content['menu'] array?
I want to add some submenu items under Site building > Menus > List menus (menu_editor module).

Of course I could just search through the tree and look at each href, to finally find the place I want to work with..

blueshack

This is a verry old post.
But after searching arroung a long time and nothing to find, I will post my solution.

I'm working with version 2.0.9.
I'm linking with a button to a forign file, which uses SSI, the theme and the global $context array, but no 'action'
So it worked, but the button was never marked as 'active' although I used $context['current_action'] like mentioned in some posts.


In subs.php ( ~ line  3198 ) $context['current_action']  get the value from $_GET['action']

so I simply set the  $_GET['action'] variable in the beginning of my script with the button name and $context['current_action'] also with the buttonname
and it worked!

Lg, Andi

NanoSector

My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Advertisement: