vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   If condition (https://vborg.vbsupport.ru/showthread.php?t=234129)

ARP 01-25-2010 02:00 PM

If condition
 
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

PHP Code:


<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

Quote:

Originally Posted by Lynne (Post 1966228)
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 :
HTML 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

Quote:

Originally Posted by ARP (Post 1966238)
Yes, I know to use ==

That's the code :
HTML 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.
PHP Code:

$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

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.
HTML Code:

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

Plug-in :
PHP Code:

$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:
HTML Code:

<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:
Code:

<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?

Code:

$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

Quote:

Originally Posted by Lynne (Post 1969007)
To see if it's the first post, use this condition:
HTML Code:

<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).

Code:

$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

Quote:

Originally Posted by Paul M (Post 1969310)
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).

Code:

$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 [DATE]1264763223[/DATE] at [TIME]1264763223[/TIME] ---------------

Quote:

Originally Posted by Lynne (Post 1969367)
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.


All times are GMT. The time now is 04:36 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01110 seconds
  • Memory Usage 1,769KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (5)bbcode_html_printable
  • (3)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (18)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete