[SOLVED] Board index: set a.subforum url to unread posts in board

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

[SOLVED] Board index: set a.subforum url to unread posts in board

Post by Gumboots »

A while back I did this: Board index: set a.row-item-link url to unread posts in board

Which is all cool and groovy, and works. So, obvious next step for UI consistency is to do the same with the subforums. Problem: how to get the equivalent of {{ forumrow.FORUM_ID }} for a subforum?

Nothing I try seems to work, and digging through functions_display.php gives me a nasty feeling that the variable I need for this is (you guessed it) not actually available in the template. I found things like this:

Code: Select all

foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
But {{ forumrow.subforum.SUBFORUM_ID }} just turns up a blank in the template, as does {{ forumrow.subforum.FORUM_ID }} or, just for the hell of it, {{ forumrow.subforum.ID }}.

{{ forumrow.subforum.FORUM_ID }} turns up the ID of the parent forum, which makes sense but is not helpful.

These here subforums have ID's. I know this. I want one. How to get?
Kthnx.

ETA: I haz a suspicion I'm gonna have to get twiggy and haul the requisite ID out of U_SUBFORUM
Last edited by Mick on Wed Aug 21, 2024 7:41 am, edited 2 times in total.
Reason: Solved.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: Board index: set a.subforum url to unread posts in board

Post by Gumboots »

MWAHAHAHA! Devious bastardry FTW. :mrgreen:

Not knowing anything at all about Twig, I did some digging. Naturally, none of the answers or docs I could find told me exactly what I wanted to know, but by trying a few guesses and white pages of death I came up with a viable method. It brought back not-so-fond-at-the-time memories of learning PHP by parse error many years ago. :lol:

Code: Select all

{% set subforumId = forumrow.subforum.U_SUBFORUM | trim('./viewforum.php?f=') %}

<a{% if forumrow.subforum.S_UNREAD %} href="{{ U_SEARCH_UNREAD }}&fid[]={{ subforumId }}"{% elseif forumrow.subforum.IS_LINK %} href="{{ forumrow.subforum.U_SUBFORUM }}"{% endif %}...
If there's no other way of getting that pesky subforum ID, this will do it. OTOH, if anyone has a cleaner way of doing it I'm all ears.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: Board index: set a.subforum url to unread posts in board

Post by Gumboots »

After a bit more testing, this appears to be the cleanest way of doing it while still having the sid appended correctly at all times.

Code: Select all

{% set subforumId = forumrow.subforum.U_SUBFORUM | split('=')[1] | split('&')[0] %}
<!-- @WIP: Syntax highlighting of next line in Notepad++ is borked, but does not bork functionality. -->
<a{% if forumrow.subforum.S_UNREAD %} href="{{ U_SEARCH_UNREAD }}&fid[]={{ subforumId }}"{% elseif forumrow.subforum.IS_LINK %} href="{{ forumrow.subforum.U_SUBFORUM }}"{% endif %}...
The code in the previous post works, but will double up on sid at times, with it being also appended after the subforum ID. This does not seem to affect functionality at all, but might as well have the cleaner url.

The WIP comment is just because I'm using Notepad++ with standard HTML syntax highlighting (the Twig UDL for it is no good for phpBB templating), so I made a note to myself. Might be useful for someone else too.

Edit: Marking as solved, since this works and nobody has come up with a better idea. :)
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6285
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

Re: [SOLVED] Board index: set a.subforum url to unread posts in board

Post by thecoalman »

You can do it with php edits, is that acceptable?
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: [SOLVED] Board index: set a.subforum url to unread posts in board

Post by Gumboots »

Lol. Well, the state religion in this part of the world declares that PHP edits are an abomination in the sight of the Lord. :D

Mind you, it's also perilously close to declaring that custom styles are an equally grave abomination, since the answer to everything seems to be "OMG you will need an extension!" even when the question is about trivial changes in presentation.

Personally I would be fine with doing PHP edits (it's not like I've never done them before) but since this is for a custom style anyway there's a certain sense to keeping it self-contained. Also, doing it in the template with Twig gets my foot in the door with Twig, which seems like it might be handy.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6285
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

Re: [SOLVED] Board index: set a.subforum url to unread posts in board

Post by thecoalman »

Well I'm not one to shy away from minor edits, especially when extension request isn't happening. ;)

I have not tested this but you can, in functions_display.php around line 496 find:

Code: Select all

						'type'		=> $subforum_row['type'],
After add:

Code: Select all

						//Mymod - Add subforum ID for template
						'sub_id'	=> $subforum_id,
Around line 580 find:

Code: Select all

				'IS_LINK'		=> $subforum['type'] == FORUM_LINK,
After add:

Code: Select all

				//Mymod - Add subforum ID for template
				'SUB_ID'		=> $subforum['sub_id'],
"Mymod" should be something unique and consistent for all edits so you can easily identify them and even search for them. You can do the same thing in templates.

Code: Select all

<!-- IF 0 -->Mymod - A comment or commented out HTML<!-- ENDIF -->
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: [SOLVED] Board index: set a.subforum url to unread posts in board

Post by Gumboots »

I had thought of doing that, or something close to it. Looks like it should work, and it would be easy to make it work even it it needed a slight tweak, but as I said I think I'll stick with doing it in the template via Twig. The template is already well past the "minor edits" stage, so keeping all the *naughty word removed* in one place makes sense to me at the moment.

I usually don't bother with the "IF 0" trick for template comments. Standard HTML comments work and are a more convenient format. Putting @WTF? before each comment makes them easy to find. :D
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦

Return to “phpBB Custom Coding”