PDA

View Full Version : <vb:if condition="$bbuserinfo[userid]"> Not Working


ExcelFox
04-13-2013, 07:55 AM
I am trying to have my BBCODE contents not viewable unless the user is logged in. I found a hack from this forum that will allow conditionals in BBCODE. I've installed that too.

What I'm trying to do is use

<vb:if condition="$bbuserinfo[userid]">
'Something here
<vb:else />
'Something else here
</vb:if>

When I try to do it as below, it gives me an error when the page is loaded

<div class="bbcode_container">
<div class="bbcode_description">{vb:rawphrase code}:&nbsp;<input type="button" value="Click To Select" onclick="selectAll(this); return false;"></div>
<pre class="bbcode_code"<vb:if condition="$vboptions['codemaxlines']">style="height:<vb:if condition="$blockheight<$vboptions['codemaxlines']">{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}*2}<vb:else />{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}}</vb:if>;"</vb:if>>
<code>
<vb:if condition="$bbuserinfo[userid]">
{vb:raw code}
<vb:else />
<b><font color="green">Hello Guest!</font></b>
<font color="black"><p>To post questions, download files, to provide solutions to queries and <b>especially to view this code</b>, <a href="register.php"><u>register for free!</u></a></p>
</vb:if>
</code>
</pre>
</div>

The original code that works is below

<div class="bbcode_container">
<div class="bbcode_description">{vb:rawphrase code}:&nbsp;<input type="button" value="Click To Select" onclick="selectAll(this); return false;"></div>
<pre class="bbcode_code"<vb:if condition="$vboptions['codemaxlines']">style="height:<vb:if condition="$blockheight<$vboptions['codemaxlines']">{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}*2}<vb:else />{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}}</vb:if>;"</vb:if>><code>{vb:raw code}</code></pre>
</div>

Any idea what's going wrong?

--------------- Added 1365846255 at 1365846255 ---------------

This isn't throwing any error. However, I am not getting the message for a guest. Instead, I am getting the actual contents of the BBCode even if a user is logged in or not

<div class="bbcode_container">
<div class="bbcode_description">{vb:rawphrase code}:&nbsp;<input type="button" value="Click To Select" onclick="selectAll(this); return false;"></div>
<pre class="bbcode_code"<vb:if condition="$vboptions['codemaxlines']">style="height:<vb:if condition="$blockheight<$vboptions['codemaxlines']">{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}*2}<vb:else />{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}}</vb:if>;"</vb:if>>
<code>

<vb:if condition="$bbuserinfo[userid]">
<b><font color="green">Hello Guest!</font></b>
<font color="black"><p>To post questions, download files, to provide solutions to queries and <b>especially to view this code</b>, <a href="register.php"><u>register for free!</u></a></p>
<vb:else />

{vb:raw code}
</vb:if>
</code>
</pre>
</div>

kh99
04-13-2013, 11:44 AM
I don't know what mod you installed to allow conditions, but normally the contents of posts are cached to avoid processing them over and over every time anyone views a thread. But the result is that conditons like yours don't work correctly unless something was done to avoid caching.

ExcelFox
04-13-2013, 12:26 PM
Thanks for your inputs. The mod that I installed is https://vborg.vbsupport.ru/showthread.php?t=149107

My objective is to mask the contents within the code wrap unless the user is logged in (not a guest). I have seen countless forums doing similar things (even this forum has something that does that). I just want to know how to do that.

Lynne
04-13-2013, 03:32 PM
Did you read all of the modification thread? You need to have post caching disabled, as Kevin stated.

ExcelFox
04-13-2013, 06:51 PM
Could you please let me know how to disable caching?

kh99
04-13-2013, 07:48 PM
In the admincp setting, under Server Settings and Optimization Options, set Cached Posts Lifespan to 0.

Christos Teriakis
04-13-2013, 08:41 PM
I'm reading it 00:30am so maybe I'm not reading well but I believe that you have the condition just the opposite:

<vb:if condition="!$bbuserinfo[userid]">
............Hello Guest!...........
<vb:else />
{vb:raw code}
</vb:if>
Also sometimes try different syntax with the same result. eg
Instead of:

$bbuserinfo[userid]
Try

$vbulletin->userinfo['userid']
And finally, is good to close all tags.... You have the <font color="black"> unclosed.

Edited: In my opinion is better to use:

<vb:if condition="$bbuserinfo[userid] > 0">

instead of:

<vb:if condition="!$bbuserinfo[userid]">

because (if I remember well such hour), even the guest are getting userid=0

Chris

kh99
04-13-2013, 11:08 PM
Edited: In my opinion is better to use:

<vb:if condition="$bbuserinfo[userid] > 0">

instead of:

<vb:if condition="!$bbuserinfo[userid]">

because (if I remember well such hour), even the guest are getting userid=0


!$bbuserinfo[userid] is true if the userid is 0, so you're right about it being the reverse but it can be used to do the same check.

Christos Teriakis
04-14-2013, 04:30 AM
Reply removed as it will leads in an endless discussion........

Chris

ExcelFox
04-14-2013, 07:28 AM
Thanks a lot everybody. It seems to be working in my forum now. I will try out the suggestions given above too. And ChrisTERis, you were right about my wrongly sequencing the conditional statement. Other than that, I am not sure about the conversion between you and Kevin (I'm sure both of you know), but I'll go with <vb:if condition="$bbuserinfo[userid] > 0">

kh99
04-14-2013, 08:50 AM
....but I'll go with <vb:if condition="$bbuserinfo[userid] > 0">

That's fine, I was just pointing out that !$bbuserinfo[userid] works to check for the userid == 0 (although obviously it's the opposite of $bbuserinfo[userid] > 0). I may just have misunderstood what Chris was saying.

ExcelFox
04-14-2013, 10:37 AM
Thanks Kevin. One last question on this topic though. Would this have worked even if I didn't install that MOD? Maybe I should be asking this question it the thread where I got the mod from, but if you have an answer that comes to mind, please let me know.

kh99
04-14-2013, 10:45 AM
Thanks Kevin. One last question on this topic though. Would this have worked even if I didn't install that MOD? Maybe I should be asking this question it the thread where I got the mod from, but if you have an answer that comes to mind, please let me know.

No, it wouldn't work, because without that mod the bbcode replacement can only be html and can't include any template tags.

Scanu
04-14-2013, 04:54 PM
<vb:if condition="$show['guest']">
Why not this?