News:

Wondering if this will always be free?  See why free is better.

Main Menu

Troubleshooting New Menu Tab?

Started by Grammy, June 06, 2016, 05:13:51 PM

Previous topic - Next topic

Grammy

I used THIS THREAD and THIS ONE as a guide.  Using TWO tutorials and I still managed to screw it up!   :D

SMF 2.0.11 default

(My forum is in my root directory; that's all the domain exists for.)


I created a new page (using a portal) that contains a breaking news widget and I wanted to put a new tab on the menu for it.  In Subs.php this is my code:

'menu_action' => array(
'title' => $txt['breaking_feed'],
'href' => 'http://mydomain.com/index.php?page=page1544',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),


In Modifications.english.php, my code is:

$txt['breaking_feed'] = 'Breaking News';

I only wanted logged in members to see it so I used 'show' => !$user_info['is_guest'], as my "show" variable.

Can you please point out why the button isn't visible?  (Bearing in mind that I am logged in but I did change it to
'show' => true,
just to see if that was the issue.)  I dumped the cache but that didn't help.  Anyone?

:-\

Antechinus

Ok, where is menu_action defined?

Grammy

Quote from: Antechinus on June 06, 2016, 05:24:33 PM
Ok, where is menu_action defined?


You should see the stupid "I have no idea" look on my face.  I guess I got lucky with another tab I'd previously added, which does show up:

Subs:  'menu_action' => array(
'title' => $txt['who'],
'href' => $scripturl . '?action=who',
'show' => $context['allow_admin'],
'icon' => '',
),


(I got tired of always typing "?action=who" so I just made a button for it, ha!)

Modifications.english.php:  $txt['who'] = 'Who';

Since that one worked, I coded it similarly for the newest one (other than the 'href'). 

So, in answer to your question...  I humbly don't know.  The new button's action is hard for me to define because it's a direct URL.  But, if you're willing to teach, I'm willing to learn.   :)

Antechinus

Aha. Ok, so you can't have two of them with the same name up front. It will chuck a wobbly over that. Call it something else.

ETA: Will look up custom actions for you too. Hang on.

Grammy

Quote from: Antechinus on June 06, 2016, 05:42:41 PM
Aha. Ok, so you can't have two of them with the same name up front. It will chuck a wobbly over that. Call it something else.

ETA: Will look up custom actions for you too. Hang on.


YES!  It "chucked a wobbly"!   :D

*hanging on*

Antechinus

Custom actions: http://wiki.simplemachines.org/smf/Add_a_custom_action

Now you don't actually need all of that stuff. All you really need for this is to define the action in index.php, if you want the tab highlighting to work the same as other menu tabs.

The rest of that page of horrors is for when someone wants to create custom pages from scratch to go with their custom action. You don't need to worry about that, since the portal is handling that for you.

Grammy

Quote from: Antechinus on June 06, 2016, 05:50:58 PM
Custom actions: http://wiki.simplemachines.org/smf/Add_a_custom_action

Now you don't actually need all of that stuff. All you really need for this is to define the action in index.php, if you want the tab highlighting to work the same as other menu tabs.

The rest of that page of horrors is for when someone wants to create custom pages from scratch to go with their custom action. You don't need to worry about that, since the portal is handling that for you.


Ah...  I don't need to actually create a custom "Youraction.php" file, just define the action?  And...  once I've done that, do I need to change the direct URL I was using?  I somehow marry that URL to the action and then call for it, as in
$scripturl . '?action=newaction',  ?

I guess what I'm asking is can a direct URL actually become an action?  (Where's the "crawl into a hole" smiley?)


EDIT:  I was looking at the 1.1.X instructions.  I clicked over to 2.0.X and have discovered the dreaded "hooks".  This could get ugly. 

Antechinus

Ok, scrap all of that. I found the easy way. :D It's been yonks since I played with this so I went looking for an old thread. I knew there was an easy way. ;)

Linking a single page to a custom action << This one isn't scary.

So anyway yes, you can use any old url in the href. That's no problem. The $current_action = 'home'; code is down beneath the menu arrays. In a default file it's on line 4164, but it'll be a bit after that in your file.

So looking at that lot I'm thinking this should work:

'breaking' => array(
'title' => $txt['breaking_feed'],
'href' => $scripturl . '?page=page1544',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),


Then down below:

if(isset($_REQUEST['action']) && strpos($_REQUEST['action'], '@page=page1544') !== false)
$current_action = 'breaking'

Grammy

Quote from: Antechinus on June 06, 2016, 06:20:05 PM
Then down below:

if(isset($_REQUEST['action']) && strpos($_REQUEST['action'], '@page=page1544') !== false)
$current_action = 'breaking'



I'm smelling the barn, now!  (That means we're getting close, ha.)

Should there be anything after $current_action = 'breaking' to close that out?  I'm getting a broken page, now.  Maybe I put it in the wrong place? 


I put:
if(isset($_REQUEST['action']) && strpos($_REQUEST['action'], '@page=page1544') !== false)
$current_action = 'breaking'


directly below:
'breaking' => array(
'title' => $txt['breaking_feed'],
'href' => $scripturl . '?page=page1544',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),


and there's a new block of code for another button just after
[code]if(isset($_REQUEST['action']) && strpos($_REQUEST['action'], '@page=page1544') !== false)
$current_action = 'breaking'
[/code]

Grammy

Actually, Antechinus, it works without the "if (isset" statement and it works beautifully.  So far, no errors.  And you, sir, are a gentleman and a scholar!  (And a rock star!)   

:D


Thanks so much!

Antechinus

Yebbut does the tab highlight when you are on that page?

And the "if (isset" statement is supposed to go further down the file, not directly below the button array. It's supposed to go after this:

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

Grammy

Quote from: Antechinus on June 06, 2016, 07:03:08 PM
Yebbut does the tab highlight when you are on that page?

And the "if (isset" statement is supposed to go further down the file, not directly below the button array. It's supposed to go after this:

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



It does highlight, and I have no errors, so SMF is apparently making an exception in my case.  I must be special.   :D

But I'll add that string where it was meant to go and dash back over with the results. 



Okay, I am golden!   

Thanks again; it's always a joy and a relief to see your name show up on one of my threads.   :)

Antechinus

Quote from: Grammy on June 06, 2016, 06:29:23 PM
Quote from: Antechinus on June 06, 2016, 06:20:05 PM
Then down below:

if(isset($_REQUEST['action']) && strpos($_REQUEST['action'], '@page=page1544') !== false)
$current_action = 'breaking'



I'm smelling the barn, now!  (That means we're getting close, ha.)

Should there be anything after $current_action = 'breaking' to close that out?  I'm getting a broken page, now.

Oh yeah. Bad syntax on my part. Should have been like this:

$current_action = 'breaking';

Grammy

Quote from: Antechinus on June 06, 2016, 07:34:27 PM


Oh yeah. Bad syntax on my part. Should have been like this:

$current_action = 'breaking';


I did get the broken page, but I took a look at all the other "if (isset" statements nearby and recklessly added the semi-colon.  That's called "desperation".   ;)

Antechinus

Hey, that's how I learned PHP too. :D

Advertisement: