SimplePortal

Social => Team Blogs => Topic started by: [SiNaN] on April 27, 2010, 06:07:08 AM

Title: Blocks In Blocks
Post by: [SiNaN] on April 27, 2010, 06:07:08 AM
I have been meaning to make a blog post about how to display blocks in blocks with SimplePortal for some time but never got to it. Seeing as we just got a request for it (here (http://simpleportal.net/index.php?topic=5320.0)), I thought I would clarify it. Are we going to add such a feature in future SimplePortal versions? Nope, certainly not, never gonna happen.

Because it's already there! Actually it has been there since version 2.0.4. In case the idea is not clear for you, have a look at this sample page here:

http://simpleportal.net/index.php?page=blocks_in_block_sample (http://simpleportal.net/index.php?page=blocks_in_block_sample)

You'll see that there are 5 blocks in total, 4 of them embedded in a single block. This is quite easy to do with SimplePortal.

First: Create the blocks you want inside the other block. Be sure the box labelled Active is not checked. This will prevent the block from being displayed anywhere else on your site.

Second: find out the ids of the blocks you just created. You can find them by looking at the link to edit the block:

httx://someforum.com/index.php?action=admin;area=portalblocks;sa=edit;block_id=2;{session_var}={session_id}

What you need is the value of block_id (here it's 2). In the example below, I'll be using 49, 50, 52, 53 as the ids of blocks.

Third: create a Custom PHP block that does just what SimplePortal normally does with blocks. Here's a sample:

Code: [Select]
$block = current(getBlockInfo(false, 49, false, false));  // Load block info
$block['style'] = sportal_parse_style('explode', $block['style'], true);  //Parse block style parameters.
template_block($block); // Output the block.

Line 1 loads the block with getBlockInfo(). Line 2 parses the block style. Line 3 finally uses that information to write it all out as HTML.

If you are putting more than one block inside your custom PHP block, you can use a table to control how they are arranged. So you can display blocks 49, 50, 52, and 53 in a custom php block like this:

Code: [Select]
$columns = 2;
$block_ids = array(49, 50, 52, 53);

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

echo '
<table style="width: 100%;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', ceil((100 / $columns)), '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table>';

You can even call the block functions, without the block template, using the proper parameters. And with some JavaScript, you can have pretty blocks like this:

http://simpleportal.net/index.php?page=blocks_in_block_sample#sp_collapse_54 (http://simpleportal.net/index.php?page=blocks_in_block_sample#sp_collapse_54)

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>';

So this is what I call "power of simplicity". I hope this gave a brief idea about how flexible and powerful SimplePortal is. If you have any questions, feel free to ask. ;)



There is also an alternative easier way explained here:

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

Edit: Fixed a minor issue with last block code.
Edit: disabled link to **** site
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on April 27, 2010, 12:13:13 PM
Wow! Before I read this, I had not figured out how the blocks got called and wrapped in their formatting wrappers.
 
I had already seen a SimplePortal user calling a block on the fly (http://simpleportal.net/index.php?topic=5195.msg31460#msg31460 (http://simpleportal.net/index.php?topic=5195.msg31460#msg31460)) to put it in the page footer, LOL.
 
If the block already exists, though, this can be even easier.
Title: Re: Blocks In Blocks
Post by: MultiformeIngegno on April 27, 2010, 01:21:27 PM
Great "tutorial"!! Thanks Sinan!!
Title: Re: Blocks In Blocks
Post by: Nas on April 27, 2010, 02:24:56 PM
That's quite cool, Sinan. :)
Title: Re: Blocks In Blocks
Post by: lakechurch on April 27, 2010, 03:05:50 PM
Very nice tutorial, works great, thanks!
Title: Re: Blocks In Blocks
Post by: dannbass on May 14, 2010, 08:01:09 PM
I'm puzzled, what if I want to add more... I thought I filled in the blanks, but it's not working... the tab appears, but the content is displayed in the second tab.
Code: [Select]
global $txt;

$txt['recent_topics'] = 'Temas';
$txt['recent_posts'] = 'Respuestas';
$txt['recent_audiciones'] = 'Audiciones';
 

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

Code: [Select]
<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>
<div id="recent_audiciones" style="display: none;">
something here
</div>
and...
Code: [Select]
document.getElementById(\'recent_topics\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'recent_posts\').style.display = current ? \'\' : \'none\';
  document.getElementById(\'recent_audiciones\').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\';
  document.getElementById(\'b_ra\').className = current ? \'button_strip_recent_audiciones active\' : \'button_strip_recent_audiciones\';

what am I doing wrong?
Thanks a lot!
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on May 27, 2010, 01:00:23 AM
What happens if the viewer does not have permission to see one of the blocks? Which of the functions (getBlockInfo, sportal_parse_style, template_block) withholds its output? What's the easiest way to detect it?
 
-----------------
Oh -- I get it.  If empty($data['type']), then you might as well skip the template_block step -- you don't have anything for output, and you'll get an error.
 
 
Title: Re: Blocks In Blocks
Post by: Shortie on May 29, 2010, 04:07:22 AM
Hi There

I have the recent topics and recent post block working great just as mentioned in the first post

My question is how can I cchange the number of items displayed to say 10

Many thanks
Title: Re: Blocks In Blocks
Post by: grafitus on May 29, 2010, 04:25:22 AM
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, 'limit' => 10), 0), '
</div>
<div id="recent_posts" style="display: none;">
   ', sp_recent(array('display' => 1, 'limit' => 10), 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>';

In short, you should add "limit => 10" parametres to sp_recent function.
Title: Re: Blocks In Blocks
Post by: Shortie on May 29, 2010, 04:26:26 AM
Great stuff grafitus

Many thanks
Title: Re: Blocks In Blocks
Post by: Shortie on May 31, 2010, 03:23:57 AM
Hi All

I have been playing with this for a few hours try to get top topics and top board in the block as well - making a total of four menu items

I can get the menu buttons okay but the rest has me beat

Is there any chance someone could give me the code

Many thanks in advance

Shortie
Title: Re: Blocks In Blocks
Post by: grafitus on June 08, 2010, 05:27:58 PM
Now that, how can we add three tabs? (E.g: For recent boards x, y, z)
Title: Re: Blocks In Blocks
Post by: ccbtimewiz on June 09, 2010, 01:43:59 AM
Extend the $buttons array
Title: Re: Blocks In Blocks
Post by: grafitus on June 09, 2010, 04:41:34 AM
Extend the $buttons array
Of course, I know it. But JavaScript not working?
Title: Re: Blocks In Blocks
Post by: Liam. on June 12, 2010, 06:03:12 PM
As soon as I try to make it a PHP block it shows a syntax error - thats with any of the code posted here...
Title: Re: Blocks In Blocks
Post by: Nathaniel on June 12, 2010, 07:41:57 PM
As soon as I try to make it a PHP block it shows a syntax error - thats with any of the code posted here...

Which specific code are you trying to use? They all work on SP 2.3.2 and SMF 2 RC3 for me.
Title: Re: Blocks In Blocks
Post by: Liam. on June 12, 2010, 07:47:33 PM
Second down in first post
Quote
Code: [Select]
$columns = 2;
$block_ids = array(49, 50, 52, 53);

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

echo '
<table style="width: 100%;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', ceil((100 / $columns)), '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table>';

But none of them are working for me; SimplePortal won't let me add the block due to a Syntax error. SMF 2.0 RC3, SP 2.3.2 - clean install.
Title: Re: Blocks In Blocks
Post by: Renegd98 on June 13, 2010, 10:16:56 AM
You need to put a checkmark in Disable PHP Validation in the general settings of Simpleportal to get these scripts to work, at least that what I had to do or I would get the same issue of syntax error.
Title: Re: Blocks In Blocks
Post by: lastrider on June 15, 2010, 07:47:44 AM
Hi,

I wanted to have two blocks side by side, however not in a parent block.

I tried this using the second bit of code, something like:
Code: [Select]
$columns = 2;
$block_ids = array(24, 23);

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

echo '
<table style="width: 100%;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', ceil((100 / $columns)), '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table>';

Disabling the Title Class will just of course get rid of the title, but would still place the two blocks in the parent block, resulting in the Title's of the two child blocks to become smaller and not fit with the rest of the portal as I would like.

Anyway I could have two blocks side by side without it being inside of another block? or at least not look like it is?
Title: Re: Blocks In Blocks
Post by: Raji on August 17, 2010, 11:25:25 AM
Hello there,

from where I can get block ID no?

Title: Re: Blocks In Blocks
Post by: AngelinaBelle on August 18, 2010, 09:31:46 AM
I've split a question from this thread and moved it to
 
http://simpleportal.net/index.php?msg=36356 (http://simpleportal.net/index.php?msg=36356)
Title: Re: Blocks In Blocks
Post by: frantic on August 24, 2010, 09:50:12 PM
I've noticed that the parent block that holds the split blocks always seems to have extra space at the bottom.  The example has it as well.  Is it possible to have the parent block snug the split blocks?
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on August 25, 2010, 09:12:21 AM
That extra space, created with a final "<br />", and part of all blocks, is found in template_block_core and template_block_curve.
Changing it would require a change to every block, unless you used a block-body strategy similar to the one I suggested in http://simpleportal.net/index.php?topic=6232.msg36445#msg36445 (http://simpleportal.net/index.php?topic=6232.msg36445#msg36445)
Here, perhaps, you would could use a custom class -- sp_no_bottom_break, for example -- in the custom body class field.  If detected, you could choose to leave out the bottom break.
 
Title: Re: Blocks In Blocks
Post by: frantic on August 25, 2010, 12:44:27 PM
Thanks Angelina, i'll try that.
Title: Re: Blocks In Blocks
Post by: thellie on August 29, 2010, 11:45:50 PM
i'd like to use the javascript version of the blocks in blocks. i want to extend it so that i can have a shoutbox in there as well, but can't get the code right.

i can do the first version myself. thanks to simple, clear instructions. but the second doesn't explain how to add other blocks into the code, in addition to the code shown - which is no help to someone with no javascript knowledge... like me.

here's the original code (version 2)...
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>';

and here's my initial attempt (i get an error at the bottom of the page as well. see below the code)
Code: [Select]
global $txt;

$txt['recent_topics'] = 'Recent Topics';
$txt['recent_posts'] = 'Recent Posts';
$txt['volunteer_shoutbox'] = 'Volunteer Chat!';

$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;',
   ),
   'volunteer_shoutbox' => array(
      'text' => 'volunteer_shoutbox',
      'image' => '',
      'lang' => true,
      'url' => '#volunteer_shoutbox" 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>
<div id="volunteer_shoutbox" 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(\'volunteer_shoutbox\').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_volunteer_shoutbox active\' : \'button_strip_volunteer_shoutbox\';
   }
// ]]></script>';

and here's the error message:
Fatal error: Call to undefined function: () in /path/to/Sources/Load.php(2124) : eval()'d code on line 173

i would think it's an issue with the
Code: [Select]
      document.getElementById(\'volunteer_shoutbox\').style.display = current ? \'\' : \'none\';

or

Code: [Select]
      document.getElementById(\'b_rp\').className = current ? \'button_strip_volunteer_shoutbox active\' : \'button_strip_volunteer_shoutbox\';

but i don't know enough (by which i mean... anything..!) about javascript to do this myself.

but if someone can help me get this right, i should be able to add other stuff using this as a guide.
thanks :)
Title: Re: Blocks In Blocks
Post by: [SiNaN] on September 30, 2010, 03:55:18 PM
I guess that example was a bit difficult for some. Here's a more simple one:

Code: [Select]
$blocks = array(
array(
'label' => 'Recent Posts',
'type' => 'sp_recent',
'parameters' => array('display' => 1),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),
array(
'label' => 'Top Posters',
'type' => 'sp_topPoster',
'parameters' => array(),
),
array(
'label' => 'Calendar',
'type' => 'sp_calendar',
'parameters' => array(),
),
);

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 with this one is; just modify the $blocks array as you like. I mean this one:

Code: [Select]
$blocks = array(
array(
'label' => 'Recent Posts',
'type' => 'sp_recent',
'parameters' => array('display' => 1),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),
array(
'label' => 'Top Posters',
'type' => 'sp_topPoster',
'parameters' => array(),
),
array(
'label' => 'Calendar',
'type' => 'sp_calendar',
'parameters' => array(),
),
);

"label" will be the block label, "type" is the block function, "parameters" is the array of block parameters.

That's all you need to do.
Title: Re: Blocks In Blocks
Post by: Divecall on September 30, 2010, 05:01:46 PM
シナン YOU ARE THE BEST !!!

Full working !

GREAT.

I found thru the i-net a nice peace of code, that i want to add for the last topics section. You have an idea how to integrate this ?

this code is to long for to post here, so i attached here.
Title: Re: Blocks In Blocks
Post by: Divecall on September 30, 2010, 06:31:08 PM
Really, that is the best code for SP ever. !  :applause: :applause: :applause:

(btw: the shoutbox is not working with this - but for me it is not necessary...)
Title: Re: Blocks In Blocks
Post by: [SiNaN] on October 01, 2010, 02:26:35 AM
I found thru the i-net a nice peace of code, that i want to add for the last topics section. You have an idea how to integrate this ?

this code is to long for to post here, so i attached here.

Make this change in the file you attached:

Code: (Find) [Select]
  $ID_MEMBER = $context['user']['id'];
  global $context, $settings, $scripturl, $txt, $db_prefix, $user_info, $modSettings, $user_profile, $smcFunc;

Code: (Replace) [Select]
<?php

  
global $context$settings$scripturl$txt$db_prefix$user_info$modSettings$user_profile$smcFunc;
  
$ID_MEMBER $context['user']['id'];

Save and upload it to Sources directory of your forum. Then at the end of the block code I gave above, add this:

Code: [Select]
function sp_custom_recent()
{
global $sourcedir;

require_once($sourcedir . '/recent post.php');
}

Then you can use 'sp_custom_recent' type in the $blocks array.

Really, that is the best code for SP ever. !  :applause: :applause: :applause:

(btw: the shoutbox is not working with this - but for me it is not necessary...)

Shoutbox will work. You need to pass a shoutbox id to parameters though, like in this example:

Code: [Select]
$blocks = array(
array(
'label' => 'Recent Posts',
'type' => 'sp_recent',
'parameters' => array('display' => 1),
),
array(
'label' => 'Shoutbox',
'type' => 'sp_shoutbox',
'parameters' => array('shoutbox_id' => 1),
),
);
Title: Re: Blocks In Blocks
Post by: Divecall on October 01, 2010, 07:12:30 AM
GREAT !

I dont know, what i can write for to show you my happiness and for to show you my thankfulness.

T*H*A*N*K  Y*O*U
Title: Re: Blocks In Blocks
Post by: Divecall on November 19, 2010, 11:27:02 AM
@シナン :

It is possible to add two tabs more:
- Show unread post since last visit
- Show new replies to your post

?
Thank you in advance, CODEMASTER  :thumbsup:
Title: Re: Blocks In Blocks
Post by: Divecall on November 19, 2010, 05:22:13 PM
...and it is possible to add this nice hover/tooltip-effect from here ?

http://simpleportal.net/index.php?topic=1332.msg8762#msg8762 (http://simpleportal.net/index.php?topic=1332.msg8762#msg8762)

sound like the umltimate-SimplePortal-Block  :D

Must be nice....

Any help is welcome !
Title: Re: Blocks In Blocks
Post by: DaRKeN on November 22, 2010, 04:08:40 PM
Hi! :)

There are some guides in Spanish for this great modification.

Thx ;)!
Title: Re: Blocks In Blocks
Post by: 130860 on November 22, 2010, 06:42:59 PM
@DaRKeN ask in the Spanish support board.
Title: Re: Blocks In Blocks
Post by: DaRKeN on November 22, 2010, 07:58:58 PM
oK, sorry and thx  :thumbsup:
Title: Re: Blocks In Blocks
Post by: MissyNL on December 23, 2010, 12:30:30 PM
Thanks so much for this tutorial! I have alway wanting to have more option for the layout of my frontpage... now it's there :) Thanks!
Title: Re: Blocks In Blocks
Post by: barbar on January 07, 2011, 02:16:43 AM
seriously when i read this i was so happy. just that i dont know how to code lol. but then again i understand how powerful and useful this thing is, now to find a way to learn how to use it :)
Title: Re: Blocks In Blocks
Post by: Old Fossil on January 16, 2011, 06:36:35 PM
Am looking into this idea with a slight difference.

on my forum www.miltonkeynesaware.co.cc/mkaforum I am looking into making a block for the following.

Traffic Updates (image link to outside source),
Bus timetable (Image link),
Train timetable ( supplied widget),
Petrol prices (supplied widget).

How would I go about this as none of the information would be called from elsewhere within the forum itself.
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on January 17, 2011, 11:30:49 AM
I assume you mean you want a block with tabs to flip between your widgets.
You do it exactly the same way. 
 
Except you can manage it without putting each widget in a block, if you like. At this point, you would not be using "blocks in blocks" at all, only php and javascript in your custom php block. Which would work just the same as it would on a standalone php page, since there is no connection to SMF at all.
Title: Re: Blocks In Blocks
Post by: nob4uask on June 07, 2011, 01:53:34 AM
Arvo All,

I just installed SP about 2 weeks ago and would like to confirm that I can do what I would like with this. 

Currently I have RSS feeds from 2 different sites and would like to have it for about 4 or 5 sites.  The problem is is that I don't want to make the page to long and also it seems to embed the RSS feed into the previous one if the page extends to far.

After looking at the sample it appears that I can label each site and have the tabs next to each other with one block.  Am I reading this correctly ?

My site is www.thedallascowboysgang.com and if you look in the middle where the RSS feeds are you will be able to tell more about what I am talking about.

Thank you for you time.
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on June 07, 2011, 06:19:22 AM
Correct. Follow the example and start simple, and you should be able to manage this.  IF you've written any code before, you'll know that you re likely to make lots of coding errors. So add only a few lines at a time to make it easier to narrow your errors down.
For support on working this through, please try the custom coding board.
 
Title: Re: Blocks In Blocks
Post by: nob4uask on June 07, 2011, 07:07:31 AM
Correct. Follow the example and start simple, and you should be able to manage this.  IF you've written any code before, you'll know that you re likely to make lots of coding errors. So add only a few lines at a time to make it easier to narrow your errors down.
For support on working this through, please try the custom coding board.

Even Angelina,

Thank you for the quick response, if I have any problems I will seek support where you recommended.

Done coding before and have the grey hairs to prove it.. :'(

Title: Re: Blocks In Blocks
Post by: unoit on July 08, 2011, 05:39:56 PM
Hi guys,

Im using the 1st set of codes that [SiNaN posted. ok im using the 1st code & 2nd code.

my problem is there a 2 blocks inside 1, but the left hand side block has 6 post & right hand side block only has 2 post in it.

how can i set it up so there is an even amount on both sides.

Title: Re: Blocks In Blocks
Post by: unoit on July 09, 2011, 06:15:35 PM



all good worked it out
Title: Re: Blocks In Blocks
Post by: Divecall on July 30, 2011, 06:26:20 PM
How to add custom-html-code in this "block-code"?

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

Thank's a lot...
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on August 23, 2011, 07:28:24 AM
I have split this question into a new topic:
Custom HTML in blocks-in-blocks (http://simpleportal.net/index.php?msg=49496)
Title: Re: Blocks In Blocks
Post by: dsantana on October 14, 2011, 05:37:48 PM
Read thru all these and didn't see if there was a way to control the block size inside of the block.
Like I want to have two blocks in my block with one having 70% and the other having 30%
Is that possible?
Title: Re: Blocks In Blocks
Post by: Raji on November 30, 2011, 03:25:49 AM
Read thru all these and didn't see if there was a way to control the block size inside of the block.
Like I want to have two blocks in my block with one having 70% and the other having 30%
Is that possible?
I am also waiting for the solution
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on November 30, 2011, 10:27:15 AM
You could always lay out your blocks-in-blocks inside a table, and set the width of the table cells. That ought to work.
Title: Re: Blocks In Blocks
Post by: iulyz on December 15, 2011, 03:01:27 PM
I guess that example was a bit difficult for some. Here's a more simple one:

Code: [Select]
$blocks = array(
array(
'label' => 'Recent Posts',
'type' => 'sp_recent',
'parameters' => array('display' => 1),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),
array(
'label' => 'Top Posters',
'type' => 'sp_topPoster',
'parameters' => array(),
),
array(
'label' => 'Calendar',
'type' => 'sp_calendar',
'parameters' => array(),
),
);

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 with this one is; just modify the $blocks array as you like. I mean this one:

Code: [Select]
$blocks = array(
array(
'label' => 'Recent Posts',
'type' => 'sp_recent',
'parameters' => array('display' => 1),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),
array(
'label' => 'Top Posters',
'type' => 'sp_topPoster',
'parameters' => array(),
),
array(
'label' => 'Calendar',
'type' => 'sp_calendar',
'parameters' => array(),
),
);

"label" will be the block label, "type" is the block function, "parameters" is the array of block parameters.

That's all you need to do.

Hi, can some one help me with a small problem. How can i display  simple ads ex: template_ad_position('below_menu');  in one of this blocs?
I do like this but is not working.
Code: [Select]
function sp_ads()
{
template_ad_position('below_menu');
}

Code: [Select]
array(
'label' => 'ads',
'type' => 'sp_ads',
'parameters' => array('display' => 1),
),
Title: Re: Blocks In Blocks
Post by: iulyz on December 19, 2011, 09:28:01 AM
find the problem tnx any way
Title: Re: Blocks In Blocks
Post by: cnashx on December 26, 2011, 07:17:34 PM
Hello.
I have been using the block with the recent topics and recent posts.
And I was wondering what code I could use to exclude forums or subforums from the recent threads or just specify certain forums or subforums.
I'm thinking about having "Recent Tropics/Threads" and another "recent" block for a specific subforum.

Thank you for your help in advance.
Title: Re: Blocks In Blocks
Post by: Kayrn on January 26, 2012, 09:50:33 AM
Hi :)

First, excuse my average english, it isn't my native langage and I hope you will understand me.

This topic was helpfull for me but I still have a problem. I need to add a rssfeed on my blocks, so I do this :

Code: [Select]
$blocks = array(
array(
'label' => 'News',
'type' => 'sp_BoardNews',
'parameters' => array(),
),
array(
'label' => 'Official News',
'type' => 'sp_rssfeed',
'parameters' => array(),
),
array(
'label' => 'Recent Posts',
'type' => 'sp_recent',
'parameters' => array('display' => 1),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),

);

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>';

But I still have a problem, because I've got an Invalid Feed error on my front page. Did someone have a solution to this ?
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on January 26, 2012, 09:56:36 AM
For the newsfeed block, you will need to supply some parameters, including the feed.
So instead of
Code: [Select]
'parameters' => array(),You want something like
Code: [Select]
'parameters' => array(
                                      'url' => 'put url of your newsfeed here, in single quotes'
                                 ),
 
Title: Re: Blocks In Blocks
Post by: Kayrn on January 26, 2012, 10:10:31 AM
Thx a lot, it works fine :)

Title: Re: Blocks In Blocks
Post by: AngelinaBelle on January 26, 2012, 10:14:29 AM
Glad to help! If you have any more questions, you can post them in the support boards.

Thanks!
Title: Re: Blocks In Blocks
Post by: Kayrn on January 26, 2012, 10:30:46 AM
Huhu, more I work, more question I have :P

So now, I have my rssfeed on my Tabs but, I need to have 10 news against of 5 at the moment. Which parameter should I put ?

Bonus Question : How did I increase Height's block ? I've got a Scroller on side and don't want it.

Title: Re: Blocks In Blocks
Post by: Zuki on January 31, 2012, 11:39:49 AM
Hi,

The response on the french-support : http://simpleportal.net/index.php?topic=10635.msg54774#msg54774

your-forum/Sources/PortalBlocks.php

function sp_rssFeed  (line 1944 about)

Quote
$count = !empty($parameters['count']) ? (int) $parameters['count'] : 5;


Change 5 for 10



Bonus Question : To change the height

your-forum/Themes/default/css/portal.css

Line 183   =>   /* Block specific styles  */

Change 300px => increase the value.

Quote
.sp_rss_flow
{
   max-height: 300px;

   overflow: auto;
}


Sorry for my poor english
Greetings
Title: Re: Blocks In Blocks
Post by: unoit on April 21, 2012, 03:30:53 AM

is there anyway to change the coding so the blocks run horizontal.

$columns = 2;
$block_ids = array(49, 50, 52, 53);

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

echo '
<table style="width: 100%;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', ceil((100 / $columns)), '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table>';
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on April 23, 2012, 07:46:57 AM
Absolutely.  Use HTML to set them up the way you want.
I recommend a nice tutorial site like w3schools.com to learn the HTML to lay out information the way you want it.
Title: Re: Blocks In Blocks
Post by: FrizzleFried on April 23, 2012, 11:17:28 AM
Thank you for this thread... because of the ability to put blocks in blocks I was able to set up my page much more efficiently...

One thing I did notice... some blocks are different sizes depending on the browser you are using.  Look at the screen shots below.  SCREENSHOT is from FF and SCREENSHOT2 is from Chrome... I'd aligned the 3 boxes within a box up in a row... looks great in Chrome... not quite so great in Firefox....  the funny thing is that the block on left and right are the SAME BLOCK but with two different settings set... yet only one seems to "shrink"?

Title: Re: Blocks In Blocks
Post by: AngelinaBelle on April 23, 2012, 02:48:40 PM
I don't know what your HTML and CSS look like for these.
With some different width controls, you might get different results.
 
If you want some help on scripting, why not open up a new topic on the support or custom coding board?
 
Anyone who is available will try to lend a hand.
Title: Re: Blocks In Blocks
Post by: FrizzleFried on April 23, 2012, 05:09:38 PM
I don't know what your HTML and CSS look like for these.
With some different width controls, you might get different results.
 
If you want some help on scripting, why not open up a new topic on the support or custom coding board?
 
Anyone who is available will try to lend a hand.

Stock DEFAULT SMF theme ...

:)

What's it called?  Curve?
Title: Re: Blocks In Blocks
Post by: ARG on April 24, 2012, 01:26:33 AM
I don't know what your HTML and CSS look like for these.
With some different width controls, you might get different results.
 
If you want some help on scripting, why not open up a new topic on the support or custom coding board?
 
Anyone who is available will try to lend a hand.

Stock DEFAULT SMF theme ...

:)

What's it called?  Curve?

It's called "Curve" but in your files it will be labeled as "default".
Title: Re: Blocks In Blocks
Post by: andy on May 21, 2012, 10:24:46 AM
I posted something in Bugs... with a comment that it probably wasn't strictly a bug    :)

It seems that permissions for blocks inside other blocks don't work. Probably ignored as those blocks are set inactive anyway.
Title: Re: Blocks In Blocks
Post by: silvershark on October 19, 2012, 09:33:02 AM
OK, I know this is an old thread, but it was a link given to me by a member on SMF. Finding the block ID is very confusing to me. I have NO coding experience and I don't understand any of this. Now I know you are going to tell me to learn, but that could take some time when all I need is this...I just need to know the block ID for the shout box so I can duplicate it on the portal. I did not understand the "file path" in the first post as to how to find it. I really need this in "stupid" talk because I just don't understand. A simple "click this, click that, click this would be great. I am using the most recent version of SP. I am so sorry to sound so dumb but I have only been doing this for 3 weeks. I understand how to edit the code I believe, I just need to know where to find the ID.

Thanks
Title: Re: Blocks In Blocks
Post by: phantomm on October 19, 2012, 09:40:55 AM
I gave you example at sm.org :)

When you go to block settings you can see ID inside URL

Quote
for example:
/index.php?action=admin;area=portalblocks;sa=edit;block_id=15;f22f830=454d3f3e280abcb5aee69e15d09ff891

In my example block ID = 15

Click at icon (http://img402.imageshack.us/img402/7803/modifyr.png) related to this block and you'll get similar URL
Title: Re: Blocks In Blocks
Post by: silvershark on October 19, 2012, 09:56:13 AM
I tried that. but I will look again.  :0
Title: Re: Blocks In Blocks
Post by: phantomm on October 19, 2012, 09:58:37 AM
but remember to go to blocks page, not Shoutbox :)
Title: Re: Blocks In Blocks
Post by: silvershark on October 19, 2012, 10:29:24 AM
OH Duh...now I get it...man I feel stupid. I was looking for a notation of the ID in the page it's self...haha! Man I am such a newb
Title: Re: Blocks In Blocks
Post by: silvershark on October 19, 2012, 10:48:49 AM
Great. it worked perfectly. Thanks for the help. I am learning as I go, but I am still very inexperienced
Title: Re: Blocks In Blocks
Post by: velorooms on October 20, 2012, 10:47:46 AM
battling this for the last hour..

Want to add a custom php block, block_id 143, to the menu so that it has new posts, new topics, unread posts..

how the blazes do you tell the array to call teh block

Code: [Select]
$blocks = array(
array(
'label' => 'Recent Posts',
'type' => 'sp_recent',
'parameters' => array('display' => 1),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),
array(
'label' => 'Unread Posts',
'type' => 'sp_block',
'parameters' => array('block_id' => 143),
),
);

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: Blocks In Blocks
Post by: andy on October 21, 2012, 01:09:51 AM
The simplest, easiest way maybe would be to make 3 blocks using the standard SMF blocks available... and perhaps a custom one from the custom blocks board if you need that.
"new posts, new topics, unread posts"

After you have made the 3 blocks (they should be set inactive) you simply put their block ID (all 3 of them) in the blocks in blocks code.
This code is in its own custom PHP block and just calls the others to display inside it using the IDs for them you provided.

You can select options to hide the titles and adjust the css of each sub block so that it looks like just one.

Title: Re: Blocks In Blocks
Post by: velorooms on October 21, 2012, 06:40:48 AM
yeh, have the three blocks and set up, but i cant get the custom block to appear. Using the code i put above with the ref as sp_block and then block_id doesnt work for me.. :S
Title: Re: Blocks In Blocks
Post by: andy on October 21, 2012, 11:48:43 AM
I think you are using the wrong piece of code. My site is working fine so you are doing something wrong.

Set the internal blocks to 'not active'. Check the viewing permissions on the main custom php block with the code below in it. Also it should be 'active',  and the internal block IDs should be in the array.

In the block list in admin you can get their IDs from the links. Just put them in the $block_ids = array(49, 50, 52, 53);
Number of columns can be set there too.



Code: [Select]
$columns = 2;
$block_ids = array(49, 50, 52, 53);

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

echo '
<table style="width: 100%;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', ceil((100 / $columns)), '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table>';
Title: Re: Blocks In Blocks
Post by: velorooms on October 22, 2012, 11:10:24 AM
Ah, theres a missunderstanding, thats not the kind of block im trying to create.

Trying to modify the example given earlier in this thread, (see screenshot)

I can add the extra menu item no problem, but i cannot get it to show the additional block using the code as below (block ref 143)

Code: [Select]
$blocks = array(
array(
'label' => 'Recent Posts',
'type' => 'sp_recent',
'parameters' => array('display' => 1),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),
array(
'label' => 'Unread Posts',
'type' => 'sp_block',
'parameters' => array('block_id' => 143),
),
);

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: Blocks In Blocks
Post by: velorooms on October 22, 2012, 11:12:08 AM
I get as far as this...

The extra button added but i dont know how to call block 143 in teh array (the block is set as non-active)

Title: Re: Blocks In Blocks
Post by: andy on October 23, 2012, 01:24:43 AM
I haven't used or tested that code - sorry I cant help with that. Hopefully someone else can.

But the way I described using the original blocks in blocks code will work - that is the easiest way I can see at the moment.
Title: Re: Blocks In Blocks
Post by: dhayzon on October 25, 2012, 02:33:54 PM
I'm using this code and I have the following error

There is a database error in your code. Please check it.

Code: [Select]
$columns = 3;

$block_ids = array(23, 22, 26, );

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

echo '
<table style="width: 60%;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', ceil((100 / $columns)), '%; vertical-align: top;">
         ', template_block($data), '

      </td>';

   $counter++;
}

echo '
   </tr>
</table>';
Title: Re: Blocks In Blocks
Post by: TinMan on October 25, 2012, 04:12:04 PM
I get as far as this...

The extra button added but i dont know how to call block 143 in teh array (the block is set as non-active)
Are you trying to do this using the Unread Posts block from Here (http://simpleportal.net/index.php?topic=11774.0)?
Title: Re: Blocks In Blocks
Post by: glennk on December 15, 2012, 07:52:20 PM
Just what I was looking for, thankyou
Title: Re: Blocks In Blocks
Post by: J Dub on January 18, 2013, 05:31:06 PM
I just want to confirm something with this one, the 'outta block' that you set other blocks in, this decides who can see them all? you cant set so differant member groups can see for example one block inside and another member group could see 2?
Title: Re: Blocks In Blocks
Post by: kaustubh on July 20, 2013, 01:20:31 PM
i want to add php custom block to block in block...

But not getting a way to do it.

My PHP code is (Planning to add smf info center in block in block)

Code: [Select]
global $context, $txt, $settings, $modSettings, $sourcedir, $user_info;

   // Get the user online list.
   require_once($sourcedir . '/Subs-MembersOnline.php');
   $membersOnlineOptions = array(
      'show_hidden' => allowedTo('moderate_forum'),
      'sort' => 'log_time',
      'reverse_sort' => true,
   );
   $context += getMembersOnlineStats($membersOnlineOptions);

   $context['show_buddies'] = !empty($user_info['buddies']);

   // Are we showing all membergroups on the board index?
   if (!empty($settings['show_group_key']))
      $context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());

   // Track most online statistics? (Subs-MembersOnline.php)
   if (!empty($modSettings['trackStats']))
      trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);

   // Retrieve the latests posts if the theme settings require it.
   if (isset($settings['number_recent_posts']) && $settings['number_recent_posts'] > 1)
   {
      $latestPostOptions = array(
         'number_posts' => $settings['number_recent_posts'],
      );
      $context['latest_posts'] = cache_quick_get('boardindex-latest_posts:' . md5($user_info['query_wanna_see_board'] . $user_info['language']), 'Subs-Recent.php', 'cache_getLastPosts', array($latestPostOptions));
   }

   $settings['display_recent_bar'] = !empty($settings['number_recent_posts']) ? $settings['number_recent_posts'] : 0;
   $settings['show_member_bar'] &= allowedTo('view_mlist');
   $context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);
   $context['show_member_list'] = allowedTo('view_mlist');
   $context['show_who'] = allowedTo('who_view') && !empty($modSettings['who_enabled']);

   // Show statistical style information...
   if ($settings['show_stats_index'])
   {
      echo '
         <div class="title_barIC">
            <h4 class="titlebg">
               <span class="ie6_header floatleft">
                  <a href="', $scripturl, '?action=stats"><img class="icon" src="', $settings['images_url'], '/icons/info.gif" alt="', $txt['forum_stats'], '" /></a>
                  ', $txt['forum_stats'], '
               </span>
            </h4>
         </div>
         <p class="infobg2">
            ', $context['common_stats']['total_posts'], ' ', $txt['posts_made'], ' ', $txt['in'], ' ', $context['common_stats']['total_topics'], ' ', $txt['topics'], ' ', $txt['by'], ' ', $context['common_stats']['total_members'], ' ', $txt['members'], '. ', !empty($settings['show_latest_member']) ? $txt['latest_member'] . ': <strong> ' . $context['common_stats']['latest_member']['link'] . '</strong>' : '', '<br />
            ', (!empty($context['latest_post']) ? $txt['latest_post'] . ': <strong>&quot;' . $context['latest_post']['link'] . '&quot;</strong>  ( ' . $context['latest_post']['time'] . ' )<br />' : ''), '
            <a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>', $context['show_stats'] ? '<br />
            <a href="' . $scripturl . '?action=stats">' . $txt['more_stats'] . '</a>' : '', '
         </p>';
   }
   // "Users online" - in order of activity.
   echo '
         <div class="title_barIC">
            <h4 class="titlebg">
               <span class="ie6_header floatleft">
                  ', $context['show_who'] ? '<a href="' . $scripturl . '?action=who' . '">' : '', '<img class="icon" src="', $settings['images_url'], '/icons/online.gif', '" alt="', $txt['online_users'], '" />', $context['show_who'] ? '</a>' : '', '
                  ', $txt['online_users'], '
               </span>
            </h4>
         </div>
         <div class="infobg2">
         <p class="inline stats">
            ', $context['show_who'] ? '<a href="' . $scripturl . '?action=who">' : '', comma_format($context['num_guests']), ' ', $context['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ' . comma_format($context['num_users_online']), ' ', $context['num_users_online'] == 1 ? $txt['user'] : $txt['users'];

   // Handle hidden users and buddies.
   $bracketList = array();
   if ($context['show_buddies'])
      $bracketList[] = comma_format($context['num_buddies']) . ' ' . ($context['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
   if (!empty($context['num_spiders']))
      $bracketList[] = comma_format($context['num_spiders']) . ' ' . ($context['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
   if (!empty($context['num_users_hidden']))
      $bracketList[] = comma_format($context['num_users_hidden']) . ' ' . $txt['hidden'];

   if (!empty($bracketList))
      echo ' (' . implode(', ', $bracketList) . ')';

   echo $context['show_who'] ? '</a>' : '', '
         </p>
         <p class="inline smalltext">';

   // Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
   if (!empty($context['users_online']))
   {
      echo '
            ', sprintf($txt['users_active'], $modSettings['lastActive']), ':<br />', implode(', ', $context['list_users_online']);

      // Showing membergroups?
      if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
         echo '
            <br />[' . implode(']&nbsp;&nbsp;[', $context['membergroups']) . ']';
   }

   echo '
         </p>
         <p class="last smalltext">
            ', $txt['most_online_today'], ': <strong>', comma_format($modSettings['mostOnlineToday']), '</strong>.
            ', $txt['most_online_ever'], ': ', comma_format($modSettings['mostOnline']), ' (', timeformat($modSettings['mostDate']), ')
         </p>
         </div>';

   // If they are logged in, but statistical information is off... show a personal message bar.
   if ($context['user']['is_logged'] && !$settings['show_stats_index'])
   {
      echo '
         <div class="title_barIC">
            <h4 class="titlebg">
               <span class="ie6_header floatleft">
                  ', $context['allow_pm'] ? '<a href="' . $scripturl . '?action=pm">' : '', '<img class="icon" src="', $settings['images_url'], '/message_sm.gif" alt="', $txt['personal_message'], '" />', $context['allow_pm'] ? '</a>' : '', '
                  <span>', $txt['personal_message'], '</span>
               </span>
            </h4>
         </div>
         <p class="pminfo">
            <strong><a href="', $scripturl, '?action=pm">', $txt['personal_message'], '</a></strong>
            <span class="smalltext">
               ', $txt['you_have'], ' ', comma_format($context['user']['messages']), ' ', $context['user']['messages'] == 1 ? $txt['message_lowercase'] : $txt['msg_alert_messages'], '.... ', $txt['click'], ' <a href="', $scripturl, '?action=pm">', $txt['here'], '</a> ', $txt['to_view'], '
            </span>
         </p>';
   }

   echo '
      </div>
   </div></div>';

How to add above php code in block in block???
Title: Re: Blocks In Blocks
Post by: AngelinaBelle on August 02, 2013, 12:28:37 PM
I would suggest putting that custom php code into a custom php block.
 
when you are satisfied with that, then explore using it inside another block.
Title: Re: Blocks In Blocks
Post by: [SiNaN] on August 14, 2013, 11:35:38 AM
If you are using the method explained in this (http://simpleportal.net/index.php?topic=5332.msg37841#msg37841) post, then you'll have to pass that whole code as the "content" parameter for sp_php block. However, it should be easier to do using the method explained at the very first post of this topic.
Title: Re: Blocks In Blocks
Post by: Divecall on September 26, 2013, 05:18:25 AM
This here:

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

is no longer working with SP 2.3.5

 :dead:
Title: Re: Blocks In Blocks
Post by: [SiNaN] on January 24, 2014, 04:23:17 PM
I'm very sorry for the extremely delayed response. Do you still require assistance with that?
Title: Re: Blocks In Blocks
Post by: FireDitto on February 10, 2014, 11:16:14 PM
You can even call the block functions, without the block template, using the proper parameters. And with some JavaScript, you can have pretty blocks like this:

http://simpleportal.net/index.php?page=blocks_in_block_sample#sp_collapse_54 (http://simpleportal.net/index.php?page=blocks_in_block_sample#sp_collapse_54)

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>';

So this is what I call "power of simplicity". I hope this gave a brief idea about how flexible and powerful SimplePortal is. If you have any questions, feel free to ask. ;)



There is also an alternative easier way explained here:

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

Edit: Fixed a minor issue with last block code.
Edit: disabled link to **** site

This is amazing; however, I can't seem to figure out how ot link to custom php blocks, as opposed to pre-made SP blocks?

This is the current code I'm using for my blocks, which also includes a piece to make sure the parent block only displays the inner blocks to the correct membergroups. I'd like to keep that aspect to it, as well, so that I can tab them all but not have X, Y or Z showing to the wrong membergroup.

This is just a regular block in block - how do I turn it into tabs?:
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 for your time! :)
Title: Re: Blocks In Blocks
Post by: 420connect on March 16, 2015, 12:12:59 PM
Carrying off where others got stuck..

What is the correct code to call custom php blocks into the javascript version to work in tabs?

I've got this far but stuck calling the other block..

Code: [Select]
$block['style'] = sportal_parse_style('explode', $block['style'], true);  //Parse block style parameters.
template_block($block); // Output the block.
$blocks = array(
                   array(
'label' => 'Chat',
'type' => 'sp_shoutbox',
'parameters' => array('display' => 1, 'shoutbox' => 2),
),
array(
'label' => 'Who`s Online',
'type' => 'sp_whosonline',
'parameters' => array('display' => 1),
),
array(
'label' => 'Recent Posts',
'type' => 'sp_php',
'parameters' => array( 'display' => 67),
),
array(
'label' => 'Unread Posts',
'type' => 'sp_recent',
'parameters' => array(),
),

);

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>';

But the Recent Posts isn't grabbing my custom block I'd like to use.. :(
Title: Re: Blocks In Blocks
Post by: ataru on April 20, 2015, 10:11:15 AM
wow. great.

someone can tell me if it is possible to alter from container block some parameter of nested block(s)?

e.g. I have a custom php block where i open a shoutbox block named "Event #1 Chat".

I want to change that #1 with #n from custom block. where can i get the title of the block and change it before the output command?

Thanks


ok. found:

Code: [Select]
$block['label']
SimplePortal 2.3.7 © 2008-2021, SimplePortal