collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 389
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ 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
  • {OCS}MasterSeal: 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

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

If you're interested in helping other members with support requests, consider joining the Community Support Helpers group.

Author Topic: Blocks In Blocks  (Read 130164 times)

0 Members and 3 Guests are viewing this topic.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
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

  • Comrade
  • *
  • Posts: 4870
  • 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

  • Comrade
  • *
  • Posts: 4870
  • 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 modsI 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 modsI don't reply support PMs. Please use support forums.

Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal 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 modsI 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 DeveloperMy 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: 102
  • 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?