SimplePortal

Support => English Support => Topic started by: FireDitto on February 07, 2014, 04:45:39 AM

Title: Tabbed Content - Blocks in Block
Post by: FireDitto on February 07, 2014, 04:45:39 AM
So~

What I would like to be able to do, if possible, is have a display block, which calls up various blocks (block in block system) but each of the blocks it calls up are tabbed so as that only one shows at a time. You click the little tab and the next block will be viewable.

This is the block in block code I'm currently using:

Code: [Select]
$block_ids = array(34, 15, 20, 26, 106, 92, 102, 79, 83, 85);

$block_data = array();
foreach ($block_ids as $block)
{
   $data = current(getBlockInfo(false, $block, false, false, true));
   if (empty($data))
      continue;
   $block_data[$block] = $data;
   $block_data[$block]['style'] = sportal_parse_style('explode', $block_data[$block]['style'], true);
}

foreach ($block_data as $data)
echo '<div>', template_block($data), '</div>';

Thank you!
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 09, 2014, 04:02:53 PM
This can absolutely be done.  One way to do it is with a little javascript.
Please see
http://simpleportal.net/index.php?topic=5332.msg32204;topicseen#msg32204
and
http://simpleportal.net/index.php?topic=5332.msg37841#msg37841

for how to do this.
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 10, 2014, 10:56:11 PM
Thanks, that's awesome!

Unfortunately I cannot find any information on how to use custom php blocks inside the tabbed content, only pre-made blocks. How would I edit the code to include custom php blocks?
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 11, 2014, 09:06:05 AM
1) First create a custom php block to use inside the tabbed content
2) Find the block id of the blocks you just created.  You will see this in the list of all of your blocks.
3) Use these block ids in your "blocks in blocks" tabbed code.
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 11, 2014, 09:53:29 AM
Okay. I already have a functioning BiB; I know how to do that. That's not what I want help with.

The TABBED block-in-block code is not nearly so easy to manipulate from my end of the screen. All the examples use pre-made SP blocks (recent_posts, for example) and there are no instruction on how to use the tabbed code with custom PHP blocks in it.

That said;

How do I edit THIS code, to read custom PHP blocks, instead of premades, preferably including individual block permissions??

Code: [Select]
global $txt;

$txt['recent_topics'] = 'Recent Topics';
$txt['recent_posts'] = 'Recent Posts';

$buttons = array(
   'recent_topics' => array(
      'text' => 'recent_topics',
      'image' => '',
      'lang' => true,
      'url' => '#recent_topics" id="b_rt" onclick="change_display(\'rp\'); return false;',
      'active' => true,
   ),
   'recent_posts' => array(
      'text' => 'recent_posts',
      'image' => '',
      'lang' => true,
      'url' => '#recent_posts" id="b_rp" onclick="change_display(\'rt\'); return false;',
   ),
);

echo '
<div style="overflow: auto;">
   ', template_button_strip($buttons), '
</div>
<div id="recent_topics">
   ', sp_recent(array('type' => 1, 'display' => 1), 0), '
</div>
<div id="recent_posts" style="display: none;">
   ', sp_recent(array('display' => 1), 0), '
</div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
   function change_display(block)
   {
      var current = block == \'rt\' ? 1 : 0;

      document.getElementById(\'recent_topics\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'recent_posts\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_recent_topics\' : \'button_strip_recent_topics active\';
      document.getElementById(\'b_rp\').className = current ? \'button_strip_recent_posts active\' : \'button_strip_recent_posts\';
   }
// ]]></script>';
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 11, 2014, 01:59:47 PM
A custom php block really does use a "premade block".  It uses the sp_php block.  One of the parameters of that block is the 'content', which is a bunch of php code.  I would not even think about trying to create a custom php block containing php code to pass to another php block.  That way lies madness.

Instead, create a custom php block.  Use function getBlockInfo  to retrieve the parameter info you need from the database.
pass that to sp_php (just as the example passes parameters to sp_recent, etc.)

It's exactly the same thing, only with the additional step of getting the $parameters off the database instead of hard-coding them in your php block with all the tabs.

Does that make sense?
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 11, 2014, 09:18:30 PM
Not in the slightest ><

I have no idea how to get the block info to obtain the parameters. The Search function on the site isn't giving me any usable information that I can see.

Could you please supply how to do that, and possibly given an example, because I have no F* idea and you are speaking Gibberish to me :(
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 11, 2014, 09:26:16 PM
Sorry.  I'll back up a bit.

First step.  Create a custom php block, for the content you would like to have in your sub-block.
Now, when you are editing that block, notice the URL for that block.

Along with some other stuff, you are going to see something like
index.php?action=admin;area=portalblocks;sa=edit;block_id=64
That number, 64, is the id number for one of my custom php blocks on a site I manage.

That block_id is just the secret code you need to get your block information out of the database.
Fortunately, [SiNaN] has provided a function called getBlockInfo.
In the original blocks-in-blocks example, you will see an example of getBlockInfo being used to get the parameters and several other things back about a block.

Can you see how you would do that?
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 12, 2014, 09:43:15 AM
I don't think we're on the same page. You're not telling me anything I don't already know; and I don't see how it relates to the tabbed BiB.

I know how to get hte block IDs - the original code I supplied in the opening post is a BIB with several individual custom PHP blocks in it. That's all well and good, looks fantastic, I love it.

However, I now want to put THOSE blocks into a BIB htat uses the tabs such as was given in the example here (http://simpleportal.net/index.php?page=blocks_in_block_sample#sp_collapse_54).

I am unable to see how to change the code to make it pull the blocks I want it to, because all the examples given for that particular code is for pre-made SP blocks, not custom made blocks.


This is the code for Tabbed BIB; What I want to know is how to change the elements to call up Custom PHP blocks that I want to be part of the tabbed system. That's all. How do I do that?:

Code: [Select]
global $txt;

$txt['recent_topics'] = 'Recent Topics';
$txt['recent_posts'] = 'Recent Posts';

$buttons = array(
   'recent_topics' => array(
      'text' => 'recent_topics',
      'image' => '',
      'lang' => true,
      'url' => '#recent_topics" id="b_rt" onclick="change_display(\'rp\'); return false;',
      'active' => true,
   ),
   'recent_posts' => array(
      'text' => 'recent_posts',
      'image' => '',
      'lang' => true,
      'url' => '#recent_posts" id="b_rp" onclick="change_display(\'rt\'); return false;',
   ),
);

echo '
<div style="overflow: auto;">
   ', template_button_strip($buttons), '
</div>
<div id="recent_topics">
   ', sp_recent(array('type' => 1, 'display' => 1), 0), '
</div>
<div id="recent_posts" style="display: none;">
   ', sp_recent(array('display' => 1), 0), '
</div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
   function change_display(block)
   {
      var current = block == \'rt\' ? 1 : 0;

      document.getElementById(\'recent_topics\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'recent_posts\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_recent_topics\' : \'button_strip_recent_topics active\';
      document.getElementById(\'b_rp\').className = current ? \'button_strip_recent_posts active\' : \'button_strip_recent_posts\';
   }
// ]]></script>';
Title: Re: Tabbed Content - Blocks in Block
Post by: Tarista on February 12, 2014, 11:00:31 AM
I'm also trying to figure out the same (i think) that you're trying to achieve FireDitto.

I tried to change some parts around from the examples I found in the links by AngelinaBelle and codes by [SiNaN]. I can't get the ID of the php to load so I guess I messed something up there. And HTML is just for adding some lines of HTML which will not be enough. Still thought i could share the code I put together with snippets of codes. At least in this version it's possible to add more tabs, and not just two. :)

Hope I'm not intruding. Feel free to ignore me if so.

This is the part I think would be most relevant if we could figure out how to make it work :)

As of now it does not seem to work. My ID of the custom block is 58 :)

Code: [Select]
array(
'label' => 'My Block',
'type' => 'sp_php',
'parameters' => array('block_id' => 58),
),

And this is the whole code
(no credit to me, I just added it up from pieces I found)
Code: [Select]
$blocks = array(
array(
'label' => 'Recent Posts',
'type' => 'sp_recent',
'parameters' => array('display' => 1),
),
array(
'label' => 'My Block',
'type' => 'sp_php',
'parameters' => array('block_id' => 58),
),
array(
'label' => 'Some HTML',
'type' => 'sp_html',
'parameters' => array('content' => 'html code goes here'),
),
);

global $txt;

$button_list = array();
foreach ($blocks as $id => $block)
{
$txt['sp_bib_label_' . $id] = $block['label'];

$button_list[] = array(
'text' => 'sp_bib_label_' . $id,
'image' => '',
'lang' => true,
'url' => '#sp_bib_' . $id . '" id="sp_bib_button_' . $id . '" onclick="sp_bib_change(' . $id . '); return false;',
);
}

$button_list[0]['active'] = true;

echo '
<div style="overflow: auto;">
', template_button_strip($button_list), '
</div>';

foreach ($blocks as $id => $block)
{
echo '
<div id="sp_bib_', $id, '"', $id != 0 ? ' style="display: none;"' : '', '>';

$block['type']($block['parameters'], 0);

echo '
</div>';
}

echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function sp_bib_change(id)
{
for (var i = 0; i < ', count($blocks), '; i++)
{
document.getElementById(\'sp_bib_\' + i).style.display = i == id ? \'\' : \'none\';
document.getElementById(\'sp_bib_button_\' + i).className = \'button_strip_\' + i + (i == id ? \' active\' : \'\');
}
}
// ]]></script>';
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 12, 2014, 04:29:16 PM
Fireditto,

Actually, I think we might be close to being on the same page.

Let us suppose that, instead of sp_recent, you want to call sp_php.  That is great.  But what do you pass into it?

First you need to get the parameters for the block.
You will want to do something like:
Code: [Select]
$block_info = getBlockInfo(,64);This will get the info for the block with id # 64.   If your php is stored in a block with a different id, then use that id number instead.

Next, you will want to get the paremeters out of there

Code: [Select]
$parameters = $block_info['parameters'];
Finally, when you get down to that line that not calls sp_recent, you will make the change to
Code: [Select]
sp_php($parameters,0)
Tarista, you are also on the right track, though you may be making your code so general-purpose that you might have a hard time debugging it.  It should work, in the end.
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 13, 2014, 01:11:09 AM
Yes! That's what I want to do.

However, your explanation has left me befuddled still. I do not know how to implement it at all into the code. Everything I'm trying is rendering the php invisible :| I'm trying to follow your instructions, but I really cant figure it out ><
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 13, 2014, 05:30:56 PM
First things first, then.

1) The php block that you want to show inside your other block.  Is that working just great?
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 13, 2014, 09:50:33 PM
The ID of the block is 15, and yes, it works perfectly fine both standalone and in the other BIB code. Just can't get it to work in the tabbed code.
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 14, 2014, 10:11:45 AM
Hey Angelina, thanks for your help by the way. I really do appreciate it.

I've looked over my blocks, and what I would like is a TABBED block that calls up:

Block ID 114 (custom PHP) as the opening block
Block ID 120 (custom PHP) as the second tab
Block ID 121 (custom PHP) as the final tab

I'm still playing with it, but I am very much failing to get it to work presently.
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 14, 2014, 08:15:12 PM
Assuming you started with working code above, you would make the changes I suggested somewhat as follows.
Remember, I have not tested this code, of course. I apologize if I have made any typing errors.

Code: [Select]
global $txt;

$blockInfo =
array (
array(
'blockName' => 'First Block',
'parameters' => getBlockInfo(,115)
),
array(
'blockName' => 'Second Block',
'parameters' => getBlockInfo(,120)
),
array(
'blockName' => 'Third Block',
'parameters' => getBlockInfo(,121)
)
);

$txt['button0'] = $blockInfo[0]['blockName'];
$txt['button1'] = $blockInfo[1]['blockName'];
$txt['button2'] = $blockInfo[2]['blockName'];



$buttons = array(
   'button0' => array(
      'text' => 'button0',
      'image' => '',
      'lang' => true,
      'url' => '#first_button" id="b_rt" onclick="change_display(\'rp\'); return false;',
      'active' => true,
   ),
   'button1' => array(
      'text' => 'button1',
      'image' => '',
      'lang' => true,
      'url' => '#second_button" id="b_rp" onclick="change_display(\'rt\'); return false;',
   ),
   'button2' => array(
      'text' => 'button2',
      'image' => '',
      'lang' => true,
      'url' => '#second_button" id="b_rp" onclick="change_display(\'rt\'); return false;',
   ),
);




echo '
<div style="overflow: auto;">
   ', template_button_strip($buttons), '
</div>
<div id="button0">
   ', sp_php($blockInfo[0]['parameters'],0), '
</div>
<div id="button1" style="display: none;">
   ', sp_php($blockInfo[1]['parameters'],0), '
</div>
<div id="button2" style="display: none;">
   ', sp_php($blockInfo[2]['parameters'],0), '
</div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
   function change_display(block)
   {
      var current = block == \'rt\' ? 1 : 0;

      document.getElementById(\'button0\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'button1\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'button2\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_button0\' : \'button_strip_button0 active\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_button1\' : \'button_strip_button1 active\';
      document.getElementById(\'b_rp\').className = current ? \'button_strip_button2 active\' : \'button_button2\';
   }
// ]]></script>';
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 14, 2014, 08:29:12 PM
It does not seem to work; I'm getting a tiny empty block that I think generally means a piece of code is wrong but not "broken"?
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 18, 2014, 04:49:05 PM
I am sorry I did not test this code.  I only made some modifications to the code from Tarista.
If this were for my forum, I would start from the basics.

I would start with just one block.

I would just try one little part, without all the fancy tabs and whatnot.

Code: [Select]
$parameters = getBlockInfo(,121);
sp_php($parameters'],0);

If that works ok, then try building the rest of it up, bit by bit.
 


Title: Re: Tabbed Content - Blocks in Block
Post by: Tarista on February 18, 2014, 04:57:31 PM
Yeah, that code seemed not to work for me either. I ended up with a blank page too. Everything else loaded fine however. Just those php blocks giving me trouble.
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 18, 2014, 05:00:28 PM
Sorry.  Untested code.  It was just a sort of "something like this" idea, and I may have messed up in the arrays or
... who knows where.

I recommend starting with the simplest possible piece (use block info, then use that to eval a php block).
Then build up from there.  You will quickly find my awful errors that way.
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 18, 2014, 10:47:09 PM
:/

The problem is, I don't know the bare basics of PHP at all. I've been playing with the code, but I honestly don't know how to change it or edit it to do... whatever it is you just said haha XD

I'll keep playing, but yeah. I know nothing xD
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 20, 2014, 03:15:27 PM
If you keep playing, you will probably learn something :)

Like I said -- take it one step at a time.  If you can
1) create php block 121 that works ( and then set block 121 inactive).
2) create another php block that just has the code I posted in http://simpleportal.net/index.php?topic=13176.msg65306#msg65306, then you will have made a good start on the whole thing.

Maybe Tarista will be interested in this, as well.
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 25, 2014, 11:23:12 PM
Yeah... I can't get it to work.
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 27, 2014, 07:12:33 PM
replace 64 with the number that is for the block you already saved -- the one that is already working.
Code: [Select]
$myBlock = 64;
$block_info = getBlockInfo(,$myBlock);
$parameters = $block_info['parameters'];
sp_php($parameters,0);


Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on February 28, 2014, 10:18:52 AM
Okay; did and tried and that code doesn't work for me either - by itself or built into any other kind of code.

I'm not a coder. I don't know how to build code, and I'm growing increasingly frustrated and upset with the half-given answers. I am not able to do this and I would really appreciate it if someone could lay out how to put a block together in simple step-by-step instructions to create a block that will function as desired. Please.
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on February 28, 2014, 12:57:39 PM
FireDitto,

I can certainly understand that you are not interested in learning to code for your site.
Unfortunately, I do not have the time to come to your site and develop this custom code for you.

If you can find a good php coder willing to help, this little project should go pretty quickly, especially if the coder has a little familiarity with SMF.

Good luck to you with this project and everything else!
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on March 01, 2014, 12:20:59 AM
I'm not asking anyone to come to my site, and I'm certainly not so stupid as to be incapable of inserting the right numbers in order to pull the correct blocks.

I hardly see how what I'm asking for is any different than what has already been asked for or offered by other people on the site, and it certainly doesn't need anyone to come to my site. All I want is the below block to call up custom PHP blocks.

Code: [Select]
global $txt;

$txt['recent_topics'] = 'Recent Topics';
$txt['recent_posts'] = 'Recent Posts';

$buttons = array(
   'recent_topics' => array(
      'text' => 'recent_topics',
      'image' => '',
      'lang' => true,
      'url' => '#recent_topics" id="b_rt" onclick="change_display(\'rp\'); return false;',
      'active' => true,
   ),
   'recent_posts' => array(
      'text' => 'recent_posts',
      'image' => '',
      'lang' => true,
      'url' => '#recent_posts" id="b_rp" onclick="change_display(\'rt\'); return false;',
   ),
);

echo '
<div style="overflow: auto;">
   ', template_button_strip($buttons), '
</div>
<div id="recent_topics">
   ', sp_recent(array('type' => 1, 'display' => 1), 0), '
</div>
<div id="recent_posts" style="display: none;">
   ', sp_recent(array('display' => 1), 0), '
</div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
   function change_display(block)
   {
      var current = block == \'rt\' ? 1 : 0;

      document.getElementById(\'recent_topics\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'recent_posts\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_recent_topics\' : \'button_strip_recent_topics active\';
      document.getElementById(\'b_rp\').className = current ? \'button_strip_recent_posts active\' : \'button_strip_recent_posts\';
   }
// ]]></script>';
Title: Re: Tabbed Content - Blocks in Block
Post by: AngelinaBelle on March 02, 2014, 05:53:24 PM
Sure, Fireditto.

Where you are calling "sp_recent", just call "sp_php" instead.  And use the code I gave you to get the parameter of the custom php block you already have working.

I am sorry I do not have the time to write and test some more code for you, on your site or on my own site.
Good Luck!
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on March 03, 2014, 08:15:33 AM
Pretty sure if it were that easy for me, I would have figured it out about a page and a half ago. Don't you think I would have tried that before asking for help? Like I said; I'm not stupid. I got the gist of the rules and I've been experimenting. My issue is that I am not knowledgeable enough to turn your whispy half-arsed replies into what I want.

I appreciate your trying to help. But to avoid further frustration, if you're not going to actually help I'd appreciate if you didn't bother; I am incredibly frustrated and feel like the past several days have been entirely wasted in regards to getting the code I want. I've stated several times, I am not a coder so giving me three or four lines and going "Try this!" doesn't help me, especially when you haven't even tested it yourself. I need to know more than that (like where it goes), and it helps if you know what you're talking about, too, which frankly, I'm doubting you do.
Title: Re: Tabbed Content - Blocks in Block
Post by: [SiNaN] on March 03, 2014, 09:56:52 AM
Ouch! That hurts. I'd rather you didn't say that to someone trying to help you. I can assure you that she is trying to help you as best as she can. I'll overlook this one as you seem to be really frustrated but I may not be as nice if this happens again. ;)

As for your question, I had an updated Blocks in Blocks code here:

http://simpleportal.net/index.php?topic=5332.msg37841#msg37841

Basically, this is the code you need:

Code: [Select]
$blocks = array(
array(
'label' => 'My Custom Block',
'type' => 'sp_php',
'parameters' => array('content' => '$some_var = "sinan"; $some_other_var = "test"; echo $some_var . $some_other_var;'),
),
);

global $txt;

$button_list = array();
foreach ($blocks as $id => $block)
{
$txt['sp_bib_label_' . $id] = $block['label'];

$button_list[] = array(
'text' => 'sp_bib_label_' . $id,
'image' => '',
'lang' => true,
'url' => '#sp_bib_' . $id . '" id="sp_bib_button_' . $id . '" onclick="sp_bib_change(' . $id . '); return false;',
);
}

$button_list[0]['active'] = true;

echo '
<div style="overflow: auto;">
', template_button_strip($button_list), '
</div>';

foreach ($blocks as $id => $block)
{
echo '
<div id="sp_bib_', $id, '"', $id != 0 ? ' style="display: none;"' : '', '>';

$block['type']($block['parameters'], 0);

echo '
</div>';
}

echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function sp_bib_change(id)
{
for (var i = 0; i < ', count($blocks), '; i++)
{
document.getElementById(\'sp_bib_\' + i).style.display = i == id ? \'\' : \'none\';
document.getElementById(\'sp_bib_button_\' + i).className = \'button_strip_\' + i + (i == id ? \' active\' : \'\');
}
}
// ]]></script>';

What you need to do is to extend the $blocks array. Here's the structure:

Code: [Select]
$blocks = array(
array(
'label' => 'My Custom Block 1', // title
'type' => 'sp_php', // type
'parameters' => array('content' => '$some_var = "sinan"; $some_other_var = "test"; echo $some_var . $some_other_var;'), // parameters
),
array(
'label' => 'My Custom Block 2', // title
'type' => 'sp_php', // type
'parameters' => array('content' => '$some_var = "sinan"; $some_other_var = "test"; echo $some_var . $some_other_var;'), // parameters
),
);

To make it easier, you can use the following code in a Custom PHP Block:

Code: [Select]
global $sourcedir;

$blocks = array(
array(
'label' => 'My Custom Block 1',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock1.php')),
),
);

global $txt;

$button_list = array();
foreach ($blocks as $id => $block)
{
$txt['sp_bib_label_' . $id] = $block['label'];

$button_list[] = array(
'text' => 'sp_bib_label_' . $id,
'image' => '',
'lang' => true,
'url' => '#sp_bib_' . $id . '" id="sp_bib_button_' . $id . '" onclick="sp_bib_change(' . $id . '); return false;',
);
}

$button_list[0]['active'] = true;

echo '
<div style="overflow: auto;">
', template_button_strip($button_list), '
</div>';

foreach ($blocks as $id => $block)
{
echo '
<div id="sp_bib_', $id, '"', $id != 0 ? ' style="display: none;"' : '', '>';

$block['type']($block['parameters'], 0);

echo '
</div>';
}

echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function sp_bib_change(id)
{
for (var i = 0; i < ', count($blocks), '; i++)
{
document.getElementById(\'sp_bib_\' + i).style.display = i == id ? \'\' : \'none\';
document.getElementById(\'sp_bib_button_\' + i).className = \'button_strip_\' + i + (i == id ? \' active\' : \'\');
}
}
// ]]></script>';

Then just create a file with the name spcustomblock1.php in ./Sources directory and put the PHP code you want for that block in that file.

If you want to add more PHP blocks, here's how you can extend $blocks array:

Code: [Select]
$blocks = array(
array(
'label' => 'My Custom Block 1',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock1.php')),
),
array(
'label' => 'My Custom Block 2',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock2.php')),
),
);

Then just create spcustomblock2.php file and put the PHP code in that file.

If you wanted to add Recent Topics block as well, you'd change $blocks array to the following:

Code: [Select]
$blocks = array(
array(
'label' => 'My Custom Block 1',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock1.php')),
),
array(
'label' => 'My Custom Block 2',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock2.php')),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),
);
Title: Re: Tabbed Content - Blocks in Block
Post by: qwert321 on March 03, 2014, 10:00:21 PM
I have been following this post as I also wanted to use the tabbed block with my own custom blocks.

I am good at manipulating already written code but not good at from scratch type of thing.

Anyhow I used your code from above Sinan and had a few issues but nothing major.

I could not get the source php files to load with the $sourcedir then noticed it was not loaded using global(at least I believe global is a means to load)

Then I kept getting an error" unexpected < " traced that down to making sure the<?php and ?> were not in the php files I was trying to load the content in.

I am not posting to say hey you missed this and that but to help out FireDitto as he/she seems to be at my level of understanding how to code.

Thanks for the help as I never would have been able to figure it out either, now I have so many more options available to customize my site.

FireDitto copy the code below and it will give you 3 tabs you can customize by changing the labels and source files you put in the source directory.

just remeber NO </php and ?> in the files you put in the source directory.

Code: [Select]
global  $sourcedir;

$blocks = array(
array(
'label' => 'Up Coming Events!',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/article_block2.php')),
),
array(
'label' => 'News!',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/article_block3.php')),
),
array(
'label' => 'Meetings!',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/article_block.php')),
),
);

global $txt;

$button_list = array();
foreach ($blocks as $id => $block)
{
$txt['sp_bib_label_' . $id] = $block['label'];

$button_list[] = array(
'text' => 'sp_bib_label_' . $id,
'image' => '',
'lang' => true,
'url' => '#sp_bib_' . $id . '" id="sp_bib_button_' . $id . '" onclick="sp_bib_change(' . $id . '); return false;',
);
}

$button_list[0]['active'] = true;

echo '
<div style="overflow: auto;">
', template_button_strip($button_list), '
</div>';

foreach ($blocks as $id => $block)
{
echo '
<div id="sp_bib_', $id, '"', $id != 0 ? ' style="display: none;"' : '', '>';

$block['type']($block['parameters'], 0);

echo '
</div>';
}

echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function sp_bib_change(id)
{
for (var i = 0; i < ', count($blocks), '; i++)
{
document.getElementById(\'sp_bib_\' + i).style.display = i == id ? \'\' : \'none\';
document.getElementById(\'sp_bib_button_\' + i).className = \'button_strip_\' + i + (i == id ? \' active\' : \'\');
}
}
// ]]></script>'; /code]
Title: Re: Tabbed Content - Blocks in Block
Post by: [SiNaN] on March 04, 2014, 01:09:55 AM
I could not get the source php files to load with the $sourcedir then noticed it was not loaded using global(at least I believe global is a means to load)

The original code does not have it and you don't need it unless you want to fetch the code from a file. It's there though in the 3rd code block of my last post which I suggested as an easier alternative.

Then I kept getting an error" unexpected < " traced that down to making sure the<?php and ?> were not in the php files I was trying to load the content in.

The code is there to handle cases both where you have the PHP open/close tags and you don't. In my tests, I had the PHP open tag. Can you attach the file that gives the error here so I can use it to debug and see where the code fails?

Thanks for the help as I never would have been able to figure it out either, now I have so many more options available to customize my site.

You're welcome. ;)
Title: Re: Tabbed Content - Blocks in Block
Post by: FireDitto on March 04, 2014, 04:35:47 AM
Thank you very much, Sinan; it works wonderfully and I really appreciate your help.
Title: Re: Tabbed Content - Blocks in Block
Post by: qwert321 on March 04, 2014, 08:51:22 AM

The code is there to handle cases both where you have the PHP open/close tags and you don't. In my tests, I had the PHP open tag. Can you attach the file that gives the error here so I can use it to debug and see where the code fails?


Funny thing I put the tags back in the file so i could attach it for you to debug and tried it again before i was going to post it and i no longer get the error.

Sorry I missed the file you had put the $global $sourcedir in

but like I said not posting to offend anyone I wish i could do this stuff from scratch.
Title: Re: Tabbed Content - Blocks in Block
Post by: [SiNaN] on March 04, 2014, 11:39:10 AM
You're both welcome!

And it's okay. I just wanted to make sure that there isn't anything I'm missing.
SimplePortal 2.3.8 © 2008-2024, SimplePortal