Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2013, 09:29 PM
TiKu's Avatar
TiKu TiKu is offline
 
Join Date: Sep 2006
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Custom Template Hook

Hi,

I want to add a template hook called 'above_header' right at the beginning of the 'header' template. So in the 'header' template I've added
Code:
{vb:raw template_hook.above_header}
.
This template hook shall be used by a plugin which hooks 'forumdisplay_start'. The code of the plugin is:
Code:
$forum = $vbulletin->forumcache["$forumid"];
$templater = vB_Template::create('ivwcode');
	$templater->register('forum', $forum);
$template_hook['above_header'] .= $templater->render();
The 'ivwcode' template currently consists of just the text "foobar".

Unfortunately the content of the 'ivwcode' template is missing in the generated HTML code. Why?

Regards
TiKu
Reply With Quote
  #2  
Old 06-06-2013, 10:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It may be that forumdisplay_start is too late, because the header can be rendered before that. You could try to set $template_hook['above_header'] to some string constant just to make sure that it's not a problem with your custom template. If you still don't see anything, try using hook parse_templates (and you'd probably want to enclose it in if (THIS_SCRIPT == 'forumdisplay') so it's not happening on every page).
Reply With Quote
  #3  
Old 06-07-2013, 06:15 AM
TiKu's Avatar
TiKu TiKu is offline
 
Join Date: Sep 2006
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you, it works with parse_templates. However, how can I get the forum info on this hook?
Reply With Quote
  #4  
Old 06-07-2013, 10:23 AM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by TiKu View Post
Thank you, it works with parse_templates. However, how can I get the forum info on this hook?
$foruminfo['forumid'] is available in the parse_templates hook.
Reply With Quote
  #5  
Old 06-07-2013, 01:04 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's true, but I think you may need a "global $foruminfo;" statement.
Reply With Quote
Благодарность от:
nhawk
  #6  
Old 06-07-2013, 01:19 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You are correct. I forgot about that.
Reply With Quote
  #7  
Old 06-07-2013, 08:41 PM
TiKu's Avatar
TiKu TiKu is offline
 
Join Date: Sep 2006
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Many thanks, after adding "global $foruminfo;", it is working.
But now I've another problem. I've added a custom field to the 'forum' table. I did this directly in phpMyAdmin, because I could not make the following installcode work:
Code:
	require_once(DIR . '/includes/class_dbalter.php');
	$db_alter = new vB_Database_Alter_MySQL($db);

	if($db_alter->fetch_table_info('forum')) {
		$db_alter->add_field(
			array(
				'name'       => 'ivw_code',
				'type'       => 'varchar',
				'length'     => '25',
				'attributes' => '',
				'null'       => true,
				'default'    => '',
				'extra'      => ''
			)
		);
	}
	unset($db_alter);
Anyway, now the SQL field is existing in the table 'forum', but in my hook, $foruminfo does not include this field: $foruminfo['ivw_code'] is not set, although the database contains data for this forum in this column. What am I doing wrong?
Reply With Quote
  #8  
Old 06-07-2013, 11:08 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think the $foruminfo array comes from the forumcache and not from a read of the database, so if you can get the forumcache updated, it should include your new field. Otherwise you'd need to read your field from the database yourself.

If you edit any forum in the forum manager it should rebuild the cache, so you can try that to see if it works. If it does, there's a function called build_forum_permissions() that you could try calling in your install code. It takes one parameter, "rebuild_genealogy" which defaults to true, but I think it's a flag for something that you don't need to do so you can probably pass false to override it (you can see the function in file includes/adminfunctions.php).
Reply With Quote
  #9  
Old 06-08-2013, 07:55 AM
TiKu's Avatar
TiKu TiKu is offline
 
Join Date: Sep 2006
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah, now I can see the field in the foruminfo array. Many thanks.

I've noticed an interesting detail: The foruminfo array contains 'ivwcode' as well as 'ivw_code'. In the database I can see only 'ivw_code', but I remember that in the beginning I had named the field 'ivwcode', without underscore, in my installer code. So it seems like the installer code somehow worked, but it did not actually create the field in the database?!

/Edit: Okay, I've added code to drop the 'ivwcode' field on uninstall and then uninstalled and reinstalled the add-on. Now the 'ivwcode' field is gone, and foruminfo contains only the 'ivw_code' field. But it does not get inserted to the database, I have to do this manually.

--------------- Added [DATE]1370685483[/DATE] at [TIME]1370685483[/TIME] ---------------

ARGH! Never mind, I'm doing all this on a test installation and my colleague has moved this test installation to a new database server without telling me. He has left the old database on the old server, so I have been looking at the wrong database all the time.

--------------- Added [DATE]1370729379[/DATE] at [TIME]1370729379[/TIME] ---------------

I have an issue with unwanted data type conversion. My custom SQL field is of type varchar(25). When it contains the string '12E03611', it will be stored as a float in the $foruminfo array. How can I force VB4 forum cache to store this as a string?
Reply With Quote
Reply


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 06:09 PM.


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.04301 seconds
  • Memory Usage 2,247KB
  • 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
  • (3)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete