MyBB Hacks

Full Version: PHp conditions in an XThreads Template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have a board with several downloads forums. They are all using the same set of Xthreads templates, just with different skins. The creators of the items for download all specialise in different fields, so it makes sense to keep them apart, and they see their forum as a mini site for them within my board.

In each of the forums in the forumdisplay threadlist I have a filter set up to filter downloads based on the Xthreads fields. It would be neat to have an option in the template to "jump" to the other creators downloads forum (this is the easy bit) but it would be VERY cool if the list could be dynamic.

For example:

in creator A's forum there are links to creators B,C and D.
in creator B's forum there are links to creators A,C and D.
in creator C's forum there are links to creators A,B and D.
in creator D's forum there are links to creators A,B and C.

I tried using the below method to "hide" the extra link but no luck. It was hidden everywhere. The list is in the forumdisplay_threadlist

HTML Code
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" style="clear: both;">
			   	<tr><td class="thead"><strong>Game</strong></td></tr>
                                <tr><td class="fancy"></td></tr>
				<tr><td class="trow1"><a href="forumdisplay.php?fid={$fid}"><span><strong>Both</strong></span></a></td></tr>
				<if $forum['fid'] == 53 then><tr><td class="trow2"><a href="{$forumurl_q}filtertf_prefix=Sims2"><span style="color: blue;"><strong>Sims2</strong></span></a></td></tr><else>
				<tr><td class="trow2"><a href="forumdisplay.php?fid={$fid}&amp;filtertf_prefix=Sims3"><span style="color: green;"><strong>Sims3</strong></span></a></td></tr>
                         </table></if>


Is there a way to do this?

You probably want to stick the </if> before </table>

I'm guessing you're using PHP in Templates plugin?
Yes, I am using php in templates. Its not that it gives an error, it just hides the link

HTML Code
                        <table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" style="clear: both;">
                        <tr><td class="thead"><strong>Game</strong></td></tr>
                                <tr><td class="fancy"></td></tr>
				<tr><td class="trow1"><a href="forumdisplay.php?fid={$fid}"><span><strong>Both</strong></span></a></td></tr>
								<if $forum['fid'] == 7 then><tr><td class="trow2"><a href="{$forumurl_q}filtertf_prefix=Sims2"><span style="color: green;"><strong>Sims2</strong></span></a></td></tr>
				<else><tr><td class="trow2"><a href="forumdisplay.php?fid={$fid}&amp;filtertf_prefix=Sims3"><span style="color: blue;"><strong>Sims3</strong></span></a></td></tr></if>
</table>



So in the code above, if I was in Forum 7 I would expect to see the link to sims2 and sims3. I just see the sims3 link. If I go to another forum using the same templates I still only see the sims 3 link. Is it because I am in forumdisplay?

Oh okay, I see what you mean.

Try using $fid instead of $forum['fid'] in the conditional (MyBB is very inconsistent, they actually use $forum_info or something like that in forumdisplay).
Hi Zinga - I'm gonna try and keep this short Smile

As in the code above, the only change being the replacements as listed below:

I tried replacing $forum['fid'] with $forum{$fid} and the result was as in my previous post - no errors, just hidden.
I tried replacing $forum['fid'] with $forumdisplay{$fid} and the result was as in my previous post - no errors, just hidden.

Then I tried replacing $forum['fid'] with {$fid} and I got an error and my whole forumdisplay was gone - just left with header and footer etc. Error as below.

Code:
Parse error: syntax error, unexpected '{', expecting ')' in /customers/leefish.nl/leefish.nl/httpd.www/mybb/forumdisplay.php(1193) : eval()'d code on line 17


So based on the output above I tried replacing $forum['fid'] with ($fid) and the result was as in my previous post - no errors, just hidden.

It should be just $fid without any surrounding brackets, though ($fid) should work too.

Here's the code I've got working:

HTML Code
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" style="clear: both;">
                        <tr><td class="thead"><strong>Game</strong></td></tr>
                                <tr><td class="fancy"></td></tr>
				<tr><td class="trow1"><a href="forumdisplay.php?fid={$fid}"><span><strong>Both</strong></span></a></td></tr>
								<if $fid == 7 then><tr><td class="trow2"><a href="{$forumurl_q}filtertf_prefix=Sims2"><span style="color: green;"><strong>Sims2</strong></span></a></td></tr>
				<else><tr><td class="trow2"><a href="forumdisplay.php?fid={$fid}&amp;filtertf_prefix=Sims3"><span style="color: blue;"><strong>Sims3</strong></span></a></td></tr></if>
</table>


BTW, for what you're doing, you may prefer a "!=" comparison rather than a "==", eg:

HTML Code
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" style="clear: both;">
                        <tr><td class="thead"><strong>Game</strong></td></tr>
                                <tr><td class="fancy"></td></tr>
				<tr><td class="trow1"><a href="forumdisplay.php?fid={$fid}"><span><strong>Both</strong></span></a></td></tr>



<if $fid != 7 then>
<tr><td class="trow2"><a href="{$forumurl_q}filtertf_prefix=Sims2"><span style="color: green;"><strong>Sims2</strong></span></a></td></tr>
</if>

<if $fid != 8 then>
<tr><td class="trow2"><a href="{$forumurl_q}filtertf_prefix=Sims3"><span style="color: green;"><strong>Sims3</strong></span></a></td></tr>
</if>

<if $fid != 9 then>
<tr><td class="trow2"><a href="{$forumurl_q}filtertf_prefix=Sims4"><span style="color: rainbow;"><strong>Sims4</strong></span></a></td></tr>
</if>

</table>

Thank you Zinga - that seems to work fine. Thank you very much. Now off to the pencil and paper to make a logical split Smile
Reference URL's