News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Homepage Context Issue

Started by Matthew K., January 14, 2010, 05:07:12 PM

Previous topic - Next topic

Matthew K.

Hey everyone,

I submitted a mod that adds your forum name to your forums title, as I've needed to use this before and I'm sure other people have as well.

However, as I'm sure people have taken note to before, if you put a code in such as ', $context['forum_name'], ' it duplicates your forum name for the index.

I have put into place a context that limits the addition of forum name to any other action except home, however when I put this context in place it doesn't show up period.

Here's my code:
<title>' . ((!$context['current_action'] == home) ? ''. $context['forum_name']. ' \'-\'' : '') . '' . $context['page_title_html_safe']. '</title>';

Thanks,
Labradoodle-360

Arantor

I suggested an alternative in PM. Does that work? Doesn't it? Errors?

As I look at that I can see it will immediately generate an error due to undefined constant, not to mention that it makes no logical sense (!$context['current_action'] will simple be false, then the expression becomes false is equal to home, which is false)

Not to mention you'll get '-' between them, not just -.
Holder of controversial views, all of which my own.


Matthew K.

Okay, your code didn't work because it was conflicting with a portal.

Uninstalled the portal, but "Forum Name" still shows on the index.

Matthew K.


Arantor

Aside from not bumping within 24 hours... do you get any errors in the error log?
Holder of controversial views, all of which my own.


Matthew K.

Only errors are related to the theme, and the menu which I am developing a mod for.

I commented out the start of my mod and cleared the errors, went through the forum and no errors in the error log.

Arantor

So if you uncomment it, do you get any errors?
Holder of controversial views, all of which my own.


Matthew K.

When I say I comment out the mod I am developing, I mean another one. Which on mouseover of "Search" and "Search Memberlist" it actually shows a search bar with a submit button like vBulletin.

Not this mod, so no errors currently with this code:    <title>' . (!($context['current_action'] == 'home') ? $context['forum_name'] . ' - ' : '') . '' . $context['page_title_html_safe']. '</title>'; Not commented out.

The current problem is it doubles "Forum Name" like: "Forum Name - Forum Name - Index" for the homepage, otherwise it works correctly, when I say correctly I mean that it shows "Forum Name - Action".

Arantor

Random question, if you go to index.php?action=boardindex, what happens then?
Holder of controversial views, all of which my own.


Matthew K.

Takes you to the homepage, no difference with the mod.

Matthew K.


smp420

How about something like


if (($context['current_action'] == 'home'))
{
echo'';
}
else
{
<title>' . ? $context['forum_name'] . ' - ' : '') . '' . $context['page_title_html_safe']. '</title>';
}
   
"Things turn out best for those who make the best of the way things turn out." -Jack Buck

Matthew K.

First of all, your code would output NO title if the action was home.

smp420

Well I dont know exactly where or what code you are trying to use I was just suggesting you use  if and else
"Things turn out best for those who make the best of the way things turn out." -Jack Buck

Arantor

The ternary operator already in use is plenty effective; I'd easily double the line count in SimpleDesk already if I had to switch out to if/else explicitly.

Obviously my memory is defective as to the action in question... follow the path through index.php for what happens on the board index and what $context['current_action'] is set to. Heck you could even throw in a trigger_error call to push an item to the error log to see what it actually is.
Holder of controversial views, all of which my own.


Matthew K.

I don't get exactly what you mean?

Arantor

I said many things. Which part?
Holder of controversial views, all of which my own.


smp420

Quote from: Arantor on January 18, 2010, 03:50:46 AM
The ternary operator already in use is plenty effective; I'd easily double the line count in SimpleDesk already if I had to switch out to if/else explicitly.

Obviously my memory is defective as to the action in question... follow the path through index.php for what happens on the board index and what $context['current_action'] is set to. Heck you could even throw in a trigger_error call to push an item to the error log to see what it actually is.
I dont get most of it what is ternary operator?
"Things turn out best for those who make the best of the way things turn out." -Jack Buck

Matthew K.

I understand the first part, I get that very well.

The part I don't understand:
Quote from: Arantorfollow the path through index.php for what happens on the board index and what $context['current_action'] is set to. Heck you could even throw in a trigger_error call to push an item to the error log to see what it actually is.

Arantor

smp420: Ternary operator = the ? : part.

For example:
$smiley = ($my_mood == "happy") ? " :) " : " :( ";
echo $smiley;


This code is functionally identical to:

if ($my_mood == "happy")
{
  $smiley = " :) ";
}
else
{
  $smiley = " :( ";
}
echo $smiley;


It is also well documented in the PHP manual.


Labradoodle: Start by looking at index.php's code. Look what the code does if no action is defined, then just mentally go through what the code is doing - especially where it actually sets up $context['current_action']. Seriously, I can't explain it any more simply - read the code, follow the path it takes.
Holder of controversial views, all of which my own.


Advertisement: