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: 357
  • 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]

Thanks for having an interest with our portal. If you have any requests for features, have a look at the Feature Requests board.

Author Topic: Tabbed Content - Blocks in Block  (Read 18975 times)

0 Members and 1 Guest are viewing this topic.

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Tabbed Content - Blocks in Block
« on: February 07, 2014, 04:45:39 AM »
So~

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

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

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

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

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

Thank you!

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #1 on: February 09, 2014, 04:02:53 PM »
This can absolutely be done.  One way to do it is with a little javascript.
Please see
http://simpleportal.net/index.php?topic=5332.msg32204;topicseen#msg32204
and
http://simpleportal.net/index.php?topic=5332.msg37841#msg37841

for how to do this.
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #2 on: February 10, 2014, 10:56:11 PM »
Thanks, that's awesome!

Unfortunately I cannot find any information on how to use custom php blocks inside the tabbed content, only pre-made blocks. How would I edit the code to include custom php blocks?

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #3 on: February 11, 2014, 09:06:05 AM »
1) First create a custom php block to use inside the tabbed content
2) Find the block id of the blocks you just created.  You will see this in the list of all of your blocks.
3) Use these block ids in your "blocks in blocks" tabbed code.
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #4 on: February 11, 2014, 09:53:29 AM »
Okay. I already have a functioning BiB; I know how to do that. That's not what I want help with.

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

That said;

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

Code: [Select]
global $txt;

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

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

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

      document.getElementById(\'recent_topics\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'recent_posts\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_recent_topics\' : \'button_strip_recent_topics active\';
      document.getElementById(\'b_rp\').className = current ? \'button_strip_recent_posts active\' : \'button_strip_recent_posts\';
   }
// ]]></script>';

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #5 on: February 11, 2014, 01:59:47 PM »
A custom php block really does use a "premade block".  It uses the sp_php block.  One of the parameters of that block is the 'content', which is a bunch of php code.  I would not even think about trying to create a custom php block containing php code to pass to another php block.  That way lies madness.

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

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

Does that make sense?
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #6 on: February 11, 2014, 09:18:30 PM »
Not in the slightest ><

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

Could you please supply how to do that, and possibly given an example, because I have no F* idea and you are speaking Gibberish to me :(

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #7 on: February 11, 2014, 09:26:16 PM »
Sorry.  I'll back up a bit.

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

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

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

Can you see how you would do that?
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #8 on: February 12, 2014, 09:43:15 AM »
I don't think we're on the same page. You're not telling me anything I don't already know; and I don't see how it relates to the tabbed BiB.

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

However, I now want to put THOSE blocks into a BIB htat uses the tabs such as was given in the example here.

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


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

Code: [Select]
global $txt;

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

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

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

      document.getElementById(\'recent_topics\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'recent_posts\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_recent_topics\' : \'button_strip_recent_topics active\';
      document.getElementById(\'b_rp\').className = current ? \'button_strip_recent_posts active\' : \'button_strip_recent_posts\';
   }
// ]]></script>';
« Last Edit: February 12, 2014, 10:13:24 AM by FireDitto »

Offline Tarista

  • Semi Newbie
  • *
  • Posts: 37
  • SMF Version: 2.0.10
  • SP Version: 2.3.5
Re: Tabbed Content - Blocks in Block
« Reply #9 on: February 12, 2014, 11:00:31 AM »
I'm also trying to figure out the same (i think) that you're trying to achieve FireDitto.

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

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

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

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

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

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

global $txt;

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

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

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

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

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

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

echo '
</div>';
}

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

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #10 on: February 12, 2014, 04:29:16 PM »
Fireditto,

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

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

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

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

Code: [Select]
$parameters = $block_info['parameters'];
Finally, when you get down to that line that not calls sp_recent, you will make the change to
Code: [Select]
sp_php($parameters,0)
Tarista, you are also on the right track, though you may be making your code so general-purpose that you might have a hard time debugging it.  It should work, in the end.
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #11 on: February 13, 2014, 01:11:09 AM »
Yes! That's what I want to do.

However, your explanation has left me befuddled still. I do not know how to implement it at all into the code. Everything I'm trying is rendering the php invisible :| I'm trying to follow your instructions, but I really cant figure it out ><

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #12 on: February 13, 2014, 05:30:56 PM »
First things first, then.

1) The php block that you want to show inside your other block.  Is that working just great?
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #13 on: February 13, 2014, 09:50:33 PM »
The ID of the block is 15, and yes, it works perfectly fine both standalone and in the other BIB code. Just can't get it to work in the tabbed code.

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #14 on: February 14, 2014, 10:11:45 AM »
Hey Angelina, thanks for your help by the way. I really do appreciate it.

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

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

I'm still playing with it, but I am very much failing to get it to work presently.

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #15 on: February 14, 2014, 08:15:12 PM »
Assuming you started with working code above, you would make the changes I suggested somewhat as follows.
Remember, I have not tested this code, of course. I apologize if I have made any typing errors.

Code: [Select]
global $txt;

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

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



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




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

      document.getElementById(\'button0\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'button1\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'button2\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_button0\' : \'button_strip_button0 active\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_button1\' : \'button_strip_button1 active\';
      document.getElementById(\'b_rp\').className = current ? \'button_strip_button2 active\' : \'button_button2\';
   }
// ]]></script>';
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #16 on: February 14, 2014, 08:29:12 PM »
It does not seem to work; I'm getting a tiny empty block that I think generally means a piece of code is wrong but not "broken"?

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #17 on: February 18, 2014, 04:49:05 PM »
I am sorry I did not test this code.  I only made some modifications to the code from Tarista.
If this were for my forum, I would start from the basics.

I would start with just one block.

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

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

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


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 Tarista

  • Semi Newbie
  • *
  • Posts: 37
  • SMF Version: 2.0.10
  • SP Version: 2.3.5
Re: Tabbed Content - Blocks in Block
« Reply #18 on: February 18, 2014, 04:57:31 PM »
Yeah, that code seemed not to work for me either. I ended up with a blank page too. Everything else loaded fine however. Just those php blocks giving me trouble.

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #19 on: February 18, 2014, 05:00:28 PM »
Sorry.  Untested code.  It was just a sort of "something like this" idea, and I may have messed up in the arrays or
... who knows where.

I recommend starting with the simplest possible piece (use block info, then use that to eval a php block).
Then build up from there.  You will quickly find my awful errors that way.
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #20 on: February 18, 2014, 10:47:09 PM »
:/

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

I'll keep playing, but yeah. I know nothing xD

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #21 on: February 20, 2014, 03:15:27 PM »
If you keep playing, you will probably learn something :)

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

Maybe Tarista will be interested in this, as well.
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #22 on: February 25, 2014, 11:23:12 PM »
Yeah... I can't get it to work.

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #23 on: February 27, 2014, 07:12:33 PM »
replace 64 with the number that is for the block you already saved -- the one that is already working.
Code: [Select]
$myBlock = 64;
$block_info = getBlockInfo(,$myBlock);
$parameters = $block_info['parameters'];
sp_php($parameters,0);


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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #24 on: February 28, 2014, 10:18:52 AM »
Okay; did and tried and that code doesn't work for me either - by itself or built into any other kind of code.

I'm not a coder. I don't know how to build code, and I'm growing increasingly frustrated and upset with the half-given answers. I am not able to do this and I would really appreciate it if someone could lay out how to put a block together in simple step-by-step instructions to create a block that will function as desired. Please.

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #25 on: February 28, 2014, 12:57:39 PM »
FireDitto,

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

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

Good luck to you with this project and everything else!
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #26 on: March 01, 2014, 12:20:59 AM »
I'm not asking anyone to come to my site, and I'm certainly not so stupid as to be incapable of inserting the right numbers in order to pull the correct blocks.

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

Code: [Select]
global $txt;

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

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

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

      document.getElementById(\'recent_topics\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'recent_posts\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_recent_topics\' : \'button_strip_recent_topics active\';
      document.getElementById(\'b_rp\').className = current ? \'button_strip_recent_posts active\' : \'button_strip_recent_posts\';
   }
// ]]></script>';

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #27 on: March 02, 2014, 05:53:24 PM »
Sure, Fireditto.

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

I am sorry I do not have the time to write and test some more code for you, on your site or on my own site.
Good Luck!
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 FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #28 on: March 03, 2014, 08:15:33 AM »
Pretty sure if it were that easy for me, I would have figured it out about a page and a half ago. Don't you think I would have tried that before asking for help? Like I said; I'm not stupid. I got the gist of the rules and I've been experimenting. My issue is that I am not knowledgeable enough to turn your whispy half-arsed replies into what I want.

I appreciate your trying to help. But to avoid further frustration, if you're not going to actually help I'd appreciate if you didn't bother; I am incredibly frustrated and feel like the past several days have been entirely wasted in regards to getting the code I want. I've stated several times, I am not a coder so giving me three or four lines and going "Try this!" doesn't help me, especially when you haven't even tested it yourself. I need to know more than that (like where it goes), and it helps if you know what you're talking about, too, which frankly, I'm doubting you do.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Tabbed Content - Blocks in Block
« Reply #29 on: March 03, 2014, 09:56:52 AM »
Ouch! That hurts. I'd rather you didn't say that to someone trying to help you. I can assure you that she is trying to help you as best as she can. I'll overlook this one as you seem to be really frustrated but I may not be as nice if this happens again. ;)

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

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

Basically, this is the code you need:

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

global $txt;

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

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

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

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

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

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

echo '
</div>';
}

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

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

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

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

Code: [Select]
global $sourcedir;

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

global $txt;

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

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

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

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

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

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

echo '
</div>';
}

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

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

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

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

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

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

Code: [Select]
$blocks = array(
array(
'label' => 'My Custom Block 1',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock1.php')),
),
array(
'label' => 'My Custom Block 2',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock2.php')),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),
);
And slowly, you come to realize... It's all as it should be...

Offline qwert321

  • Newbie
  • Posts: 4
  • SMF Version: 2.0.7
  • SP Version: 2.3.4
Re: Tabbed Content - Blocks in Block
« Reply #30 on: March 03, 2014, 10:00:21 PM »
I have been following this post as I also wanted to use the tabbed block with my own custom blocks.

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

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

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

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

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

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

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

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

Code: [Select]
global  $sourcedir;

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

global $txt;

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

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

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

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

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

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

echo '
</div>';
}

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

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Tabbed Content - Blocks in Block
« Reply #31 on: March 04, 2014, 01:09:55 AM »
I could not get the source php files to load with the $sourcedir then noticed it was not loaded using global(at least I believe global is a means to load)

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

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

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

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

You're welcome. ;)
And slowly, you come to realize... It's all as it should be...

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #32 on: March 04, 2014, 04:35:47 AM »
Thank you very much, Sinan; it works wonderfully and I really appreciate your help.

Offline qwert321

  • Newbie
  • Posts: 4
  • SMF Version: 2.0.7
  • SP Version: 2.3.4
Re: Tabbed Content - Blocks in Block
« Reply #33 on: March 04, 2014, 08:51:22 AM »

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


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

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

but like I said not posting to offend anyone I wish i could do this stuff from scratch.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Tabbed Content - Blocks in Block
« Reply #34 on: March 04, 2014, 11:39:10 AM »
You're both welcome!

And it's okay. I just wanted to make sure that there isn't anything I'm missing.
And slowly, you come to realize... It's all as it should be...