collapse

* User Info

 
 
Welcome, Guest. Please login or register.
Did you miss your activation email?

* Who's Online

  • Dot Guests: 105
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 pm
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 pm
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 pm
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 pm
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 am
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 am
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 am
  • emanuele: [link]
    November 01, 2016, 12:43:50 pm
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 pm
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 am
  • [DFg]DJF-1975: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 am
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 pm
  • phantomm: and from what I see only patch is broken, full install package is fine
    October 21, 2016, 03:44:44 pm
  • phantomm: they say it for over 3 weeks now..
    October 21, 2016, 03:43:52 pm
  • aegersz: SMF say that bug fix 2.0.13 is coming soon ...
    October 19, 2016, 06:46:12 pm
  • Chen Zhen: check that thread at a later date as that file is not a final fix
    October 10, 2016, 03:09:18 pm
  • [DFg]DJF-1975: Thanks for the shoutbox fix file!
    October 10, 2016, 09:17:19 am
  • * Burke Knight Lurks
    October 02, 2016, 09:17:45 pm
  • [DFg]DJF-1975: Not to shoutbox spam, but I use this portal daily and I wanted to say thank you. It's been too long since I last thanked you all!
    October 02, 2016, 11:52:06 am

* Recent Posts

Modificar y Editar el estilo del titulo de un bloque by aelmiger
[Yesterday at 11:30:04 pm]


Re: Page in PHP page by emanuele
[March 20, 2017, 12:10:42 pm]


Page in PHP page by solarsailor
[March 19, 2017, 08:45:41 am]


Re: Potential bug, much weirdness by Chen Zhen
[March 07, 2017, 12:14:52 pm]


Re: Potential bug, much weirdness by CoreISP
[March 06, 2017, 03:13:05 pm]

Installation errors? Mod incompatibilities? Upgrade problems? Make your way over to the Install and Upgrade Support board for all your solutions!

Author Topic: Blocks In Blocks  (Read 77690 times)

0 Members and 1 Guest are viewing this topic.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.10
  • SP Version: 2.3.6
Blocks In Blocks
« 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), 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

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

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
« Last Edit: August 14, 2013, 11:34:09 am by [SiNaN] »
And slowly, you come to realize... It's all as it should be...

Offline AngelinaBelle

  • Support
  • *
  • Posts: 4871
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Blocks In Blocks
« Reply #1 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) to put it in the page footer, LOL.
 
If the block already exists, though, this can be even easier.
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Offline MultiformeIngegno

  • Full Member
  • ***
  • Posts: 127
  • Gender: Male
  • SMF Version: None
  • SP Version: None
Re: Blocks In Blocks
« Reply #2 on: April 27, 2010, 01:21:27 pm »
Great "tutorial"!! Thanks Sinan!!

Offline Nas

  • Comrade
  • *
  • Posts: 35
  • Gender: Male
  • SimpleDesk UI Developer
    • SimpleDesk
  • SMF Version: 2 RC3
  • SP Version: None
Re: Blocks In Blocks
« Reply #3 on: April 27, 2010, 02:24:56 pm »
That's quite cool, Sinan. :)

Offline lakechurch

  • Semi Newbie
  • *
  • Posts: 6
  • SMF Version: None
  • SP Version: None
Re: Blocks In Blocks
« Reply #4 on: April 27, 2010, 03:05:50 pm »
Very nice tutorial, works great, thanks!

Offline dannbass

  • Semi Newbie
  • *
  • Posts: 16
  • Gender: Male
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Blocks In Blocks
« Reply #5 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!

Offline AngelinaBelle

  • Support
  • *
  • Posts: 4871
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Blocks In Blocks
« Reply #6 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.
 
 
« Last Edit: May 27, 2010, 01:39:11 am by AngelinaBelle »
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Offline Shortie

  • Semi Newbie
  • *
  • Posts: 21
  • The Art OF Graphics
    • Graphics Mayhem
  • SMF Version: 2 RC2
  • SP Version: 2.3.1
Re: Blocks In Blocks
« Reply #7 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

Offline grafitus

  • Comrade
  • *
  • Posts: 1554
  • Gender: Male
  • just looking for own old energy
  • SMF Version: None
  • SP Version: None
Re: Blocks In Blocks
« Reply #8 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.
my mods
I don't reply support PMs. Please use support forums.

Offline Shortie

  • Semi Newbie
  • *
  • Posts: 21
  • The Art OF Graphics
    • Graphics Mayhem
  • SMF Version: 2 RC2
  • SP Version: 2.3.1
Re: Blocks In Blocks
« Reply #9 on: May 29, 2010, 04:26:26 am »
Great stuff grafitus

Many thanks

Offline Shortie

  • Semi Newbie
  • *
  • Posts: 21
  • The Art OF Graphics
    • Graphics Mayhem
  • SMF Version: 2 RC2
  • SP Version: 2.3.1
Re: Blocks In Blocks
« Reply #10 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

Offline grafitus

  • Comrade
  • *
  • Posts: 1554
  • Gender: Male
  • just looking for own old energy
  • SMF Version: None
  • SP Version: None
Re: Blocks In Blocks
« Reply #11 on: June 08, 2010, 05:27:58 pm »
Now that, how can we add three tabs? (E.g: For recent boards x, y, z)
my mods
I don't reply support PMs. Please use support forums.

Offline Sayaka

  • Hero Member
  • *****
  • Posts: 2163
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: 2.0.13
  • SP Version: 2.3.6
  • Elkarte Version: None
Re: Blocks In Blocks
« Reply #12 on: June 09, 2010, 01:43:59 am »
Extend the $buttons array

Offline grafitus

  • Comrade
  • *
  • Posts: 1554
  • Gender: Male
  • just looking for own old energy
  • SMF Version: None
  • SP Version: None
Re: Blocks In Blocks
« Reply #13 on: June 09, 2010, 04:41:34 am »
Extend the $buttons array
Of course, I know it. But JavaScript not working?
« Last Edit: November 22, 2011, 11:00:22 am by grafitus »
my mods
I don't reply support PMs. Please use support forums.

Offline Liam.

  • Semi Newbie
  • *
  • Posts: 9
  • Gender: Male
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Blocks In Blocks
« Reply #14 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...

Offline Nathaniel

  • Comrade
  • *
  • Posts: 5203
  • Gender: Male
    • Verbtest.com
  • SMF Version: 2 RC4
  • SP Version: 2.3.3
Re: Blocks In Blocks
« Reply #15 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.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

Offline Liam.

  • Semi Newbie
  • *
  • Posts: 9
  • Gender: Male
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Blocks In Blocks
« Reply #16 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.

Offline Renegd98

  • Semi Newbie
  • *
  • Posts: 49
  • SMF Version: 2 RC2
  • SP Version: 2.3.1
Re: Blocks In Blocks
« Reply #17 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.

Offline lastrider

  • Just Registered
  • Posts: 1
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Blocks In Blocks
« Reply #18 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?

Offline Raji

  • Full Member
  • ***
  • Posts: 101
  • Gender: Female
    • Baaskani Diwwan
  • SMF Version: 2.0.1
  • SP Version: 2.3.4
Re: Blocks In Blocks
« Reply #19 on: August 17, 2010, 11:25:25 am »
Hello there,

from where I can get block ID no?