1
Coplan
Blocks
  • 2004/4/7 5:34

  • Coplan

  • Just popping in

  • Posts: 51

  • Since: 2002/10/2


Could someone shed some light on the subject of blocks? I'm coding a module, and I want to code some blocks for it. Unfortunately, I can't find the necessary docs in Wiki, and the search hasn't brought up anything useful. Is there some secret documentation somewhere?

I have the block info defined in the xoops_version.php file. I have the block template set up. I even have a function defined within the blocks directory. But at that point, I'm lost. The block (whcih is really just a template file at this point) isn't showing at all...and I have permission to view it, and it is set to visible.

And now I'm just frustrated.

Any help would be greatly appreciated.

2
Dave_L
Re: Blocks
  • 2004/4/7 8:50

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


One undocumented fact is that the show-function, which sets up the template variables for the block's template, must return a non-empty array.

For example:

function b_modulename_show($options)
{
   
$block = array();
   
$block['foo'] = 'bar'// dummy value for now, to ensure array isn't empty
   
return $block;
}


If you don't do that, the function that calls the show-function simply exits with no error indication. (It took me a few hours of debugging to figure that out. )

I'm also in the process of writing a block for my module. If I come across any other peculiarities, I'll post back here (if I remember).

3
worlds
Re: Blocks
  • 2004/4/7 8:50

  • worlds

  • Just popping in

  • Posts: 61

  • Since: 2004/3/13


I know exactly how you feel. I had the same experience when starting to write for xoops.

I don't know if it's worth much, but I wrote up an article on debugging xoops, and posted it on my site.

http://www.worldware.com/modules/sections/index.php?op=viewarticle&artid=2

I don't know if it will help. Most of it is obvious. Right after someone tells you

Comments are welcome.

Tom

4
worlds
Sample Trivial Block for Debugging
  • 2004/4/7 9:22

  • worlds

  • Just popping in

  • Posts: 61

  • Since: 2004/3/13


Hi -

One of the things I did when I was getting annoyed writing blocks, was write a debug block. It's just about the simplest block you can do, so there's very little to go wrong. I can start by installing it, then I can make sure I have everything right for the simple case. Then I can add code from my real block, until I can see what causes a problem.

Note that while I was just off cleaning this up, it was not showing up for me, even after repeated reloads of the module. I uninstalled the module, and re-installed it, and there it was. So try that, too.


Here are the parts of my block:

from xoops_version.php:
$modversion['blocks'][1]['file'] = "debugblock.php";
$modversion['blocks'][1]['name'] = "Bookstore: Debug Block";
$modversion['blocks'][1]['description'] = "Only used for debugging";
$modversion['blocks'][1]['show_func'] = "b_bookstore_debug";
$modversion['blocks'][1]['template'] = 'bookstore_debug.html';


Start your block indexes at 1, not zero.!

And this forum keeps changing the code I'm posting below for debugblock.php. It keeps turning my urls in debugblock.php into a hyperlink.

So when copying and pasting the section below, make sure you paste the code below as text, not HTML. the values in the array should just be
h t t p : // http://www.worldware.com, and not
a href h t t p: // http://www.worldware.com

Note to XOOPS team: things within code blocks should not be altered. That's a bug!

blocks\debugblock.php:


function b_bookstore_debug()

{
$sites = array
(
"xoops.org" => "https://xoops.org",
"worldware.com" => "http://www.worldware.com"
);
$block = array();
$link = array();
foreach ($sites as $site => $url)
{
$link['site'] = $site;
$link['url'] = $url;
$block['links'][] = $link;
}
return $block;
}
?>


templates\blocks\bookstore_debug.html:
<div class="blockContent">
    <
table border="3">
        <{foreach 
item=link from=$block.links}>
        <
tr>
            <
td><a href="<{$link.url}>"><{$link.site}>a>td>
        tr>
        <{/foreach}>
    table>
div>

5
worlds
Re: Blocks
  • 2004/4/7 9:25

  • worlds

  • Just popping in

  • Posts: 61

  • Since: 2004/3/13


It's sort of a feature. If your database query returns 0 rows, then the block doesn't show.

It's usually what you want.

Except maybe when debugging.

Tom

6
Dave_L
Re: Blocks
  • 2004/4/7 9:45

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I guess that makes sense. But most of my time is spent debugging, so ...

7
Mithrandir
Re: Blocks

If your block relies on database queries, the queries will still show up in MySQL debug if enabled.

8
Coplan
Re: Blocks
  • 2004/4/9 4:57

  • Coplan

  • Just popping in

  • Posts: 51

  • Since: 2002/10/2


Okay...the module seems to be working pretty well now. The whole $block thing was throwing me for a loop, as it isn't typical of the smarty stuff I've been using for the rest of the module.

I have one more related question though:

My module is set up so that there's a common php script that gets included into each script. This file is called functions.php. In the blocks routines, however, I am not able to include this file.

The blocks file is in "tunetracker/blocks/tt_blocks.php"
The functions script is in "tunetracker/functions.php"

I was using the command "include('../functions.php'), but alas, it doesn't seem to be loading.

What should I do here to be able to include that file?

Thanks for the help.

9
Mithrandir
Re: Blocks

try with
include_once (XOOPS_ROOT_PATH.'/modules/tunetracker/functions.php');

and also use include_once in your module pages or you will get a fatal error due to the same function being defined twice.

10
Coplan
Re: Blocks
  • 2004/4/13 15:56

  • Coplan

  • Just popping in

  • Posts: 51

  • Since: 2002/10/2


I tried that...and all I get is a blank screen (no errors, nothing). I'll continue to trouble-shoot...but I have no idea why that one line could cause the problem.

Login

Who's Online

377 user(s) are online (279 user(s) are browsing Support Forums)


Members: 0


Guests: 377


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits