Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 10-02-2014, 12:36 AM
hilaryl hilaryl is offline
 
Join Date: Jan 2006
Location: Brisbane, Australia
Posts: 110
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Use array from plugin in template as conditional

Hey Guys,

I have read a lot about using variables from plugins inside the FORUMDISPLAY template. But nothing really covers what I'm trying to do.

What I'm trying to do is create a conditional based on specific parent forumids - but using an array.

I can access the parentlist id's on a page using
Code:
{vb:raw $foruminfo[parentlist]}
The parentlist is equal to something like '690,610,-1' (current forumid,parent forumid,no parent).

Once I have that, I want to basically say, if 'parentlist' CONTAINS '610' then show this.

I know you can't do a CONTAINS conditional that way because vbulletin doesn't allow it, and the parenlist is just a string, not an array.

So I need to make a plugin to turn the parentlist into and array. Then register it for use in the FORUMDISPLAY template. For that I used
PHP Code:
$parentarray explode(','$foruminfo[parentlist]);
vB_Template::preRegister('FORUMDISPLAY'$parentarray); 
The hook location for this plugin is set to parse_templates.

Now I want to say in my FORUMDISPLAY template. If $parentarray CONTAINS '610' then show this. For which is used:
Code:
<vb:if condition="in_array(610, parentarray)"><!-- It's working --></vb:if>
That doesn't validate in the template though, which is where I'm looking for some guidance.

I believe everything is working up to the conditional statement, and I'm not sure if I'm accessing the parentarray variable in the right way.

Any help would be appreciated.

Thanks,
hilaryl
Reply With Quote
  #2  
Old 10-02-2014, 01:07 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quick look without reading... ( I will do that later... dinner is calling )

Code:
   <vb:if condition="in_array(610, $parentarray)"></vb:if>
The hook location is fine.
Reply With Quote
  #3  
Old 10-02-2014, 02:18 AM
hilaryl hilaryl is offline
 
Join Date: Jan 2006
Location: Brisbane, Australia
Posts: 110
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by tbworld View Post
Quick look without reading... ( I will do that later... dinner is calling )

Code:
   <vb:if condition="in_array(610, $parentarray))"></vb:if>
The hook location is fine.
I'm not sure if you have typed that correctly or not...but that would mean there would be two close brackets and only one open bracket?

As well as the addition of the '$' before the variable.

Thanks for your quick reply!

Cheers
Reply With Quote
  #4  
Old 10-02-2014, 02:53 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yep, I typed it quickly and the last paren should be removed. Sorry about that. I corrected the post above. Keep the '$'.

I was holding up dinner, and I was suppose to be grilling the steaks.

Are you testing on a live hosted board or a local test board? If you are on a local test board add conditionally some diagnostic functions to the safe_functions array. Even "var_dump" can be useful to see if you passed the correct data and type.
Reply With Quote
  #5  
Old 10-02-2014, 03:53 AM
hilaryl hilaryl is offline
 
Join Date: Jan 2006
Location: Brisbane, Australia
Posts: 110
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by tbworld View Post
Yep, I typed it quickly and the last paren should be removed. Sorry about that. I corrected the post above. Keep the '$'.

I was holding up dinner, and I was suppose to be grilling the steaks.

Are you testing on a live hosted board or a local test board? If you are on a local test board add conditionally some diagnostic functions to the safe_functions array. Even "var_dump" can be useful to see if you passed the correct data and type.
Haha I appreciate your dedication!

We are on a live server, so my changes are live.

Upon adding the '$', I still get an error message when I 'Save and Reload'.
Code:
Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3555

The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
Should I just click continue and then make the change?

I would prefer it if what I was doing was legit in terms of vBulletin validation.

Cheers
Reply With Quote
  #6  
Old 10-02-2014, 04:49 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am now looking into this. I am reproducing your results. It was not doing this on my main system. but then I run a different lexical/parser setup. When I checked it against (vb 4.2.2, vb 4.2.1) -- I received the same error.

This problem might have been around a while. As this sure seems similar.
https://vborg.vbsupport.ru/showthread.php?t=109915
Reply With Quote
  #7  
Old 10-02-2014, 04:58 AM
hilaryl hilaryl is offline
 
Join Date: Jan 2006
Location: Brisbane, Australia
Posts: 110
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

We are running vBulletin 4.1.9 Patch Level 4

Cheers
Reply With Quote
  #8  
Old 10-02-2014, 05:08 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Still testing...
Reply With Quote
  #9  
Old 10-02-2014, 05:33 AM
hilaryl hilaryl is offline
 
Join Date: Jan 2006
Location: Brisbane, Australia
Posts: 110
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by tbworld View Post
Still testing...
Thanks tbworld! I really appreciate your help with this.

I've had a read of the link you gave above. It appears to be exactly the same problem, however it doesn't appear to be solved.

I don't think the in_array() is the issue, because the FORUMDISPLAY template was able to validate the following, and it works as a conditionally statement too.

Code:
<vb:if condition="in_array(610, array(610,690,-1))"><!-- It's Working --></vb:if>
It must have something to do with using a variable as the actual array.

Cheers
Reply With Quote
  #10  
Old 10-02-2014, 05:48 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In line (78) of template search_common.

Code:
   <vb:if condition="in_array($type, $selectedtypes)"> checked="checked"</vb:if>
vb4.2.1 it parses.
vb4.2.2 it fails.

Does the conditional work correctly, if you force the saving of the template?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:16 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.17655 seconds
  • Memory Usage 2,261KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_code
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete