PDA

View Full Version : If condition


ARP
01-25-2010, 02:00 PM
Hello all,

I'm trying to use some text in the first post so in vb3 was

<if condition="(($post[postcount] == 1))">

And now what's the new code with vb4 ?

Thanks.

Lynne
01-25-2010, 02:20 PM
Have you tried that condition? (except replace <if with <vb:if and </if> with </vb:if> )

wolfe
01-25-2010, 02:35 PM
try this m8



<vb:if condition="$post[postcount] = 1"> text </vb:if>

and for <else /> its now <vb:else />

ARP
01-25-2010, 02:55 PM
Lynne, Tried it now but it doesn't work.

wolfe, the code appear in all posts

Lynne
01-25-2010, 03:13 PM
You need to use == , not =

When saying something doesn't work, you need to post exactly what you are trying AND tell us exactly where in what template you are putting it.

ARP
01-25-2010, 03:28 PM
You need to use == , not =

When saying something doesn't work, you need to post exactly what you are trying AND tell us exactly where in what template you are putting it.

Yes, I know to use ==

That's the code :
<vb:if condition="$post[postcount] == 1">
{vb:raw thread.title}
</vb:if>
And using template hook postbit end and the plugin postbit_display_complete

Lynne
01-25-2010, 03:54 PM
I don't see anything in there about a template_hook. And, how is this related to using the postbit_display_complete hook location? I thought you were just editing one of the postbit templates. That code will not work in a plugin - it isn't proper php.

Digital Jedi
01-25-2010, 04:19 PM
Yes, I know to use ==

That's the code :
<vb:if condition="$post[postcount] == 1">
{vb:raw thread.title}
</vb:if>
And using template hook postbit end and the plugin postbit_display_complete
That's why you need to be specific as to what your doing. Template conditionals never worked in plugins on any version of vB.

ARP
01-26-2010, 09:44 AM
Yes Guys, I know all of that. What I had posted above that's my template and the plugin is that.
$templater = vB_Template::create('ARP_TEMPLATE');

$template_hook["postbit_end"] .= $templater->render();

Lynne
01-26-2010, 02:06 PM
So it's a custom template and you are using both the $post and $thread variables in it.... Did you register them for use in that template? If not, then you won't be able to use them in there. Read this article on registering variables - [vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)

ARP
01-28-2010, 01:40 PM
OK Lynne, It's registered now, However the first post condition doesn't work and If I remove the If tag it's working and rendering the template.
<vb:if condition="$post[postcount] == 1">
{vb:raw arp_var}
</vb:if>
Plug-in :
$arp_var = "{vb:raw thread.title}";

$templater = vB_Template::create('ARP_TEMPLATE');
$templater->register('arp_var', $arp_var);
$template_hook["postbit_end"] .= $templater->render();

I Sure the plug-in is correct and it's render the template and working fine If I remove the if tags. So the problem now what's the first post if condition ?

Lynne
01-28-2010, 02:43 PM
To see if it's the first post, use this condition:
<vb:if condition="$post['postid'] == $thread['firstpostid']">
{vb:raw arp_var}
</vb:if>

(You are the second person in less than 12 hours to bring up that the postcount condition doesn't work. I'm not sure why and haven't had a chance to look into it - sleep got in the way. :) )

James Birkett
01-28-2010, 07:08 PM
Could it be that you are using 1, the boolean value for true?

Have you tried:
<vb:if condition="$post[postcount] == '1'">{vb:raw arp_var}</vb:if>

derfelix
01-28-2010, 07:18 PM
shouldnt you also register post variable in your template?

$arp_var = "{vb:raw thread.title}";

$templater = vB_Template::create('ARP_TEMPLATE');
$templater->register('arp_var', $arp_var);
$templater->register('post', $post);
$template_hook["postbit_end"] .= $templater->render();

just a thought..
F.

ARP
01-28-2010, 08:39 PM
To see if it's the first post, use this condition:
<vb:if condition="$post['postid'] == $thread['firstpostid']">
{vb:raw arp_var}
</vb:if>

(You are the second person in less than 12 hours to bring up that the postcount condition doesn't work. I'm not sure why and haven't had a chance to look into it - sleep got in the way. :) )

It's doesn't work :(, Maybe It's a vbulletin bug ? Please check vbulletin files again lynne. Thanks for your time.

Also all other suggests doesn't work.

Paul M
01-28-2010, 09:12 PM
There is no bug, you must register any variables used in the template, including those in the conditionals (certain ones like $show are auto available).

In you case, you must register both $post and $thread (in blue).

$arp_var = "{vb:raw thread.title}";

$templater = vB_Template::create('ARP_TEMPLATE');
$templater->register('arp_var', $arp_var);
$templater->register('post', $post);
$templater->register('thread', $thread);
$template_hook["postbit_end"] .= $templater->render();


Also, I dont know what the line is red is for, but all you will output is the text {vb:raw thread.title}

Lynne
01-28-2010, 10:54 PM
You haven't registered the $thread variable for use in your template, so it's not going to work.

Any variable array you want to use in a template must be registered.

ARP
01-29-2010, 09:06 AM
There is no bug, you must register any variables used in the template, including those in the conditionals (certain ones like $show are auto available).

In you case, you must register both $post and $thread (in blue).

$arp_var = "{vb:raw thread.title}";

$templater = vB_Template::create('ARP_TEMPLATE');
$templater->register('arp_var', $arp_var);
$templater->register('post', $post);
$templater->register('thread', $thread);
$template_hook["postbit_end"] .= $templater->render();


Also, I dont know what the line is red is for, but all you will output is the text {vb:raw thread.title}

You are great my friend, It's worked perfect and thanks to MARCO1 Who have send to me the working if condition for the first post.

Thanks All is working now.

--------------- Added 1264763223 at 1264763223 ---------------

You haven't registered the $thread variable for use in your template, so it's not going to work.

Any variable array you want to use in a template must be registered.

Thanks Lynne for your help and your great support.