Wired1
05-15-2010, 08:14 AM
Source Articles:
[HOW TO - vB4] Adding a New Tab in Member Profile (https://vborg.vbsupport.ru/showthread.php?t=235860)
[HOW TO - vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)
[How-to] Add more tabs to the vB 3.7 profile pages (https://vborg.vbsupport.ru/showthread.php?t=165554) (I know, but some of it still applies when you look at the current 4.03 code)
Note: attached (as well as at the bottom of this post) is my current test project to get more acquainted with the new vB 4.0 code and template system. Yes, I'm fully aware of the junk code that's still in there. No worries, it's commented out!
As an exercise I'm trying to build a new member profile tab with a profile block inside of it. Using the articles above I've managed to create the tab and output basic variables and array data, however I can't output variables from within the ProfileBlock class. I've been looking over the code in class_profileblock.php and member.php for a clue, but I can't figure out what's calling the class itself, so there's a gap in the logic path I'm trying to follow to figure it out!
Any idea how to get the data from block_data['mymodification'] within the ProfileBlock out to the template? I've gotta be missing something basic :D Yes, there's a couple of lines of test code still in there that probably don't make sense anymore lol :)
Also as a side question: Do you need to pre-register templates for templates that are within a Product? (don't think so, but can't hurt to ask!)
<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="extratab" active="1">
<title><![CDATA[TEST TITLE]]></title>
<description><![CDATA[TEST DESCRIPTION]]></description>
<version></version>
<dependencies>
</dependencies>
<codes>
</codes>
<templates>
<template name="my_data_tab" templatetype="template" date="" username="" version=""><![CDATA[
<dd<vb:if condition="$selected_tab == 'test'"> class="selected"</vb:if>><a id="test-tab" href="{vb:raw relpath}#test" onclick="return tabViewPicker(this);">Test</a></dd>
]]></template>
<template name="my_data_data" templatetype="template" date="" username="" version=""><![CDATA[
<div id="view-test" class="<vb:if condition="$selected_tab == 'test'">selected_view_section<vb:else />view_section</vb:if>">
<div class="blockbody">
<div class="blockrow">
<ul class="friends_list floatcontainer">
my_var = {vb:raw my_var}</br>
my_array = {vb:raw my_array}</br>
my_array.key1 = {vb:raw my_array.key1}</br>
my_array.key2.key21 = {vb:raw my_array.key2.key21}</br>
</br>
block_data = {vb:raw block_data}</br>
block_data.mymodification = {vb:raw block_data.mymodification}</br>
</br>
my_insertvar = {vb:raw my_insertvar}}</br>
my_insertvar.my_var = {vb:raw my_insertvar.my_var}}</br>
</ul>
</div>
</div>
</div>
]]></template>
</templates>
<plugins>
<plugin active="1" executionorder="5">
<title>Caches Tab</title>
<hookname>cache_templates</hookname>
<phpcode><![CDATA[if (THIS_SCRIPT == 'member')
{
$cache = array_merge((array)$cache,array(
'my_data_tab',
'my_data_data'
));
}
]]></phpcode>
</plugin>
<plugin active="1" executionorder="5">
<title>Test Tab</title>
<hookname>member_build_blocks_start</hookname>
<phpcode><![CDATA[
$templater = vB_Template::create('my_data_tab');
$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);
$template_hook['profile_tabs_last'] .= $templater->render();
//$blocklist = array_merge($blocklist, array(
// 'mymodification' => array(
// 'class' => 'MyModification',
// 'title' => 'My Modification',
// 'hook_location' => 'profile_left_last'
// )
//));
class vB_ProfileBlock_MyModification extends vB_ProfileBlock
{
var $template_name = 'my_data_data';
function confirm_empty_wrap()
{ return false; }
function confirm_display()
{
return ($this->block_data['mymodification'] != '');
//return false;
//return true;
}
function prepare_output($id = '', $options = array())
{ $this->block_data['mymodification'] = 'Content to show in the tab.'; }
}
//Do your processing to get your data ready here.
$my_var = "abc";
$my_array = array(
'key1' => 'value1',
'key2' => array(
'key21' => 'value21',
'key22' => 'value22'
)
);
//vB_Template::preRegister('my_data_data',array('blo ck_data' => $block_data));
$templater = vB_Template::create('my_data_data');
$templater->register('my_var', $my_var);
$templater->register('my_array', $my_array);
$templater->register('block_data', $block_data);
$templater->register('selected_tab', $selected_tab);
$template_hook['profile_tabs'] .= $templater->render();
$templatevalues['my_insertvar'] = $templater->render();
vB_Template::preRegister('my_data_data', $templatevalues);
]]></phpcode>
</plugin>
</plugins>
<phrases>
</phrases>
<options>
</options>
<helptopics>
</helptopics>
<cronentries>
</cronentries>
<faqentries>
</faqentries>
</product>
[HOW TO - vB4] Adding a New Tab in Member Profile (https://vborg.vbsupport.ru/showthread.php?t=235860)
[HOW TO - vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)
[How-to] Add more tabs to the vB 3.7 profile pages (https://vborg.vbsupport.ru/showthread.php?t=165554) (I know, but some of it still applies when you look at the current 4.03 code)
Note: attached (as well as at the bottom of this post) is my current test project to get more acquainted with the new vB 4.0 code and template system. Yes, I'm fully aware of the junk code that's still in there. No worries, it's commented out!
As an exercise I'm trying to build a new member profile tab with a profile block inside of it. Using the articles above I've managed to create the tab and output basic variables and array data, however I can't output variables from within the ProfileBlock class. I've been looking over the code in class_profileblock.php and member.php for a clue, but I can't figure out what's calling the class itself, so there's a gap in the logic path I'm trying to follow to figure it out!
Any idea how to get the data from block_data['mymodification'] within the ProfileBlock out to the template? I've gotta be missing something basic :D Yes, there's a couple of lines of test code still in there that probably don't make sense anymore lol :)
Also as a side question: Do you need to pre-register templates for templates that are within a Product? (don't think so, but can't hurt to ask!)
<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="extratab" active="1">
<title><![CDATA[TEST TITLE]]></title>
<description><![CDATA[TEST DESCRIPTION]]></description>
<version></version>
<dependencies>
</dependencies>
<codes>
</codes>
<templates>
<template name="my_data_tab" templatetype="template" date="" username="" version=""><![CDATA[
<dd<vb:if condition="$selected_tab == 'test'"> class="selected"</vb:if>><a id="test-tab" href="{vb:raw relpath}#test" onclick="return tabViewPicker(this);">Test</a></dd>
]]></template>
<template name="my_data_data" templatetype="template" date="" username="" version=""><![CDATA[
<div id="view-test" class="<vb:if condition="$selected_tab == 'test'">selected_view_section<vb:else />view_section</vb:if>">
<div class="blockbody">
<div class="blockrow">
<ul class="friends_list floatcontainer">
my_var = {vb:raw my_var}</br>
my_array = {vb:raw my_array}</br>
my_array.key1 = {vb:raw my_array.key1}</br>
my_array.key2.key21 = {vb:raw my_array.key2.key21}</br>
</br>
block_data = {vb:raw block_data}</br>
block_data.mymodification = {vb:raw block_data.mymodification}</br>
</br>
my_insertvar = {vb:raw my_insertvar}}</br>
my_insertvar.my_var = {vb:raw my_insertvar.my_var}}</br>
</ul>
</div>
</div>
</div>
]]></template>
</templates>
<plugins>
<plugin active="1" executionorder="5">
<title>Caches Tab</title>
<hookname>cache_templates</hookname>
<phpcode><![CDATA[if (THIS_SCRIPT == 'member')
{
$cache = array_merge((array)$cache,array(
'my_data_tab',
'my_data_data'
));
}
]]></phpcode>
</plugin>
<plugin active="1" executionorder="5">
<title>Test Tab</title>
<hookname>member_build_blocks_start</hookname>
<phpcode><![CDATA[
$templater = vB_Template::create('my_data_tab');
$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);
$template_hook['profile_tabs_last'] .= $templater->render();
//$blocklist = array_merge($blocklist, array(
// 'mymodification' => array(
// 'class' => 'MyModification',
// 'title' => 'My Modification',
// 'hook_location' => 'profile_left_last'
// )
//));
class vB_ProfileBlock_MyModification extends vB_ProfileBlock
{
var $template_name = 'my_data_data';
function confirm_empty_wrap()
{ return false; }
function confirm_display()
{
return ($this->block_data['mymodification'] != '');
//return false;
//return true;
}
function prepare_output($id = '', $options = array())
{ $this->block_data['mymodification'] = 'Content to show in the tab.'; }
}
//Do your processing to get your data ready here.
$my_var = "abc";
$my_array = array(
'key1' => 'value1',
'key2' => array(
'key21' => 'value21',
'key22' => 'value22'
)
);
//vB_Template::preRegister('my_data_data',array('blo ck_data' => $block_data));
$templater = vB_Template::create('my_data_data');
$templater->register('my_var', $my_var);
$templater->register('my_array', $my_array);
$templater->register('block_data', $block_data);
$templater->register('selected_tab', $selected_tab);
$template_hook['profile_tabs'] .= $templater->render();
$templatevalues['my_insertvar'] = $templater->render();
vB_Template::preRegister('my_data_data', $templatevalues);
]]></phpcode>
</plugin>
</plugins>
<phrases>
</phrases>
<options>
</options>
<helptopics>
</helptopics>
<cronentries>
</cronentries>
<faqentries>
</faqentries>
</product>