Welcome to Geeklog, Anonymous Wednesday, October 09 2024 @ 09:59 am EDT

Geeklog Forums

Controlling blocks


Status: offline

Euan

Forum User
Full Member
Registered: 04/22/02
Posts: 292
One problem I often find is the control of blocks.... sometimes, I want to use different blocks for different parts of the site.

With static pages, I have got over this by creating "inline blocks" - basically, parsing the page for [[IB function_name]] and then calling that function and replacing in the block HTML (code coming later).

With plugins, it is a little more difficult. For example, I don't want to show the topics block except when viewing stories - other times, I show my own menu. When browing the links, it is not important that the user knows there is a topic called "dull stories from my last holiday in Bournemouth".

I think the short answer to this is that the option for determining when to show a block (in the block manager) should have the options:

Always (always show the block)
All topics (but not in plugins)
... normal topics listed here.....

To do this, you need to:

1) edit layout/theme/admin/blocks.thtml to add a new "notplugins" category.
2) edit admin/blocks.php to populate the new "notplugins" values.
3) edit lib-common.php (COM_showBlocks) to check for this:
Text Formatted Code

    if( !empty( $topic ))
    {
        $sql .= " AND (tid = '$topic' OR (tid = 'all' AND type <> 'layout') OR (tid = 'notplugins'))";
    }

 


And I think that was all I did. I think this would be useful (and not difficult) to add to Geeklog core. Any takers?

Cheers,

Euan.
-- Heather Engineering
-- No job too small
 Quote

Status: offline

Blaine

Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
excited
Actually Euan,

You will want to look at some of the changes we made in GL 1.3.10. As a developer, you can now call COM_siteHeader and COM_siteFooter to show a custom list of blocks on the left (via siteHeader) or right (via siteFooter).

The functions now check if an array is being passed in. This array can specify a custom function used to format the blocks. We broke out the code to retrieve and format the blocks and there is now a COM_formatBlock function.

What's needed in a custom function is some basic logic to retrieve the needed blocks and call COM_formatBlock. We have added a working example of this in lib-cutom call custom_showBlocks.

The following is an example of how this can be used as is.
A basic index.php that will show the a custom list of blocks on the left and rght.
Text Formatted Code

<?php

require_once("lib-common.php");

$myblocks_left = array ('section_block','myblock1','poll_block');
$myblocks_right = array ('whosonline_block','events_block','poll_block');

/* Show Custom list of Blocks */
echo COM_siteHeader( array('COM_showCustomBlocks',$myblocks_left) ) ;
echo  COM_siteFooter( true, array('COM_showCustomBlocks',$myblocks_right));

?>

 



I think this is a very powerfull new feature in GL 1.3.10. You can use the custom_showBlocks function or write your own if you need additional logic or control.


Geeklog components by PortalParts -- www.portalparts.com
 Quote

Status: offline

Euan

Forum User
Full Member
Registered: 04/22/02
Posts: 292
Aha. One step behind the team as ever.

This is perfect - this means I can tweak my plugins to call different blocks left and right - excellent stuff. I guess it would be good then to have plugins check their config.php for the blocks to show...? and just show default (to be set in the site's config.php) if there is nothing defined. That would make sense and make it easy for lazy people. Now who would that be....

Cheers,

Euan.
-- Heather Engineering
-- No job too small
 Quote

All times are EDT. The time is now 09:59 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content