Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Antechinus on May 16, 2022, 07:22:25 PM

Title: 2.1 body tag ternary: me wants area too!
Post by: Antechinus on May 16, 2022, 07:22:25 PM
Ok, default ternary (ZOMFG) is this...
<body id="', $context['browser_body_id'], '" class="action_', !empty($context['current_action']) ? $context['current_action'] : (!empty($context['current_board']) ?
'messageindex' : (!empty($context['current_topic']) ? 'display' : 'home')), !empty($context['current_board']) ? ' board_' . $context['current_board'] : '', '">';

I want to do this (ie: with action and area) but it doesn't echo the area to the body tag.
<body id="', $context['browser_body_id'], '" class="action_', !empty($context['current_action']) ? $context['current_action'] : (!empty($context['current_board']) ?
'messageindex' : (!empty($context['current_topic']) ? 'display' : 'home')), !empty($context['current_board']) ? ' board_' . $context['current_board'] : '', !empty($context['current_area']) ? ' area_' . $context['current_area'] : '', '">';

Why not? What gives? Who stole my area, and can I get it back?
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: live627 on May 16, 2022, 11:45:44 PM
Do a var_dump() to confirm the existence of your variable. It should throw an undefined index.

You need to either define it yourself in template_init() or read the request param manually.

https://github.com/SimpleMachines/SMF/search?q=current_area
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Antechinus on May 17, 2022, 01:11:58 AM
Sounds gnarly.
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: live627 on May 17, 2022, 10:57:11 AM
Welcome to the world of code, where things work in unexpected ways, things you think might solve the problem don't, require more code and time than was planned for, and poor documentation all around.
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Antechinus on May 17, 2022, 11:36:09 AM
Lol. I was well aware of that already.

However, I'll have to post that cartoon about dogs again...
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Sesquipedalian on May 17, 2022, 01:20:37 PM
You can post that cartoon about talking to dogs again if you like. It was amusing.

But if you want to be able to change the code to fit your desired outcomes, it's up to you to learn how the code works so that you can. Your cartoon about talking to dogs is funny because the human uses human language in an attempt to get the dog to do what the human wants. But if the dog decides it wants to argue about politics at human dinner parties, the dog can't very well complain that people keep talking with words instead of barking.
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Antechinus on May 17, 2022, 01:29:31 PM
Fair point, but on a support forum the dog might expect a few tips on basic English.
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Sesquipedalian on May 17, 2022, 01:34:44 PM
live627 gave you some good pointers already. ;)
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Arantor on May 17, 2022, 01:40:05 PM
Looks like it's $context['admin_area'] for admin and moderation area, $context['menu_item_selected'] for PM area and profile area.

Any other user of generic menu may not export it at all.
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Antechinus on May 17, 2022, 01:45:58 PM
I might try replacing the ternary with the modified array I used in 2.0.x for this. Clearer and easier to read anyway, and seems easier to modify.

Ternaries rapidly get ridiculous once you get past a simple if : else.
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Arantor on May 17, 2022, 01:48:34 PM
Downside is it might not actually work because there were a LOT of changes in 2.1...
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Antechinus on May 17, 2022, 01:51:08 PM
Learn by breaking things ;)
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: Antechinus on May 17, 2022, 02:09:11 PM
Well that's a total bummer. The old array works flawlessly, is extremely easy to modify, and makes for cleaner HTML. Whoopee. :D

ETA: And goes in function template_html_above() not function template_init()
The former already has $context as global, so it just works.

Although obviously I could add $context as a global to template_init() if there was any benefit in having the array in that function.
Title: Re: 2.1 body tag ternary: me wants area too!
Post by: live627 on May 17, 2022, 11:24:32 PM
Quote from: Antechinus on May 17, 2022, 02:09:11 PMAlthough obviously I could add $context as a global to template_init() if there was any benefit in having the array in that function.
it's optics/organization