Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Blocks to appear in more than just the left or right column #707

Closed
eSilverStrike opened this issue Dec 16, 2016 · 3 comments
Closed
Milestone

Comments

@eSilverStrike
Copy link
Member

With the next version of Geeklog (2.2.0) we will be dropping support for COM_SiteHeader and COM_SiteFooter.

This would be an ideal time to also update the way we handle blocks and their location on the page. It would be nice to either have more areas (ie Header, Footer, Left, Right) or better yet allow the theme to define their own set of one or more block locations.

Lots of thought will have to go into this feature as we want to minimize the changes as much as possible for backwards compatibility.

@eSilverStrike
Copy link
Member Author

Maybe also allow blocks to use template views?

eSilverStrike added a commit that referenced this issue Mar 12, 2018
Custom block locations can be assigned by a theme and or plugin. For feature request #707
@eSilverStrike
Copy link
Member Author

eSilverStrike commented Mar 12, 2018

Okay...

Blocks can now appear in other positions/locations besides left or right. This includes either a theme template or a plugin specific template. Blocks in custom locations can only appear when the function PLG_templateSetVars is called on a template and the location is setup before hand by the theme or plugin.

For a complete example of how to setup a custom block location in a plugin check out the Forum plugin repository.

For an overview example -The below code is added to the forum functions.php file to add a blocks location where topic posts are shown. If a plugin custom block location is only available in a certain theme then the function below (with the updated function name forum_getBlockLocations_denim_three) would be added to the plugins templates functions.php file for the specified theme.

/**
 * Return an array of Block Locations in plugin templates
 */
function plugin_getBlockLocations_forum()
{
    global $LANG_GF20;
    
    $block_locations = array();

    // Add any extra block locations for plugin
    // Remember these locations can only appear in templates that PLG_templateSetVars is used with
    $block_locations[] = array(
        'id'                => 'forum_showtopic', // Unique string. No other block location (includes Geeklog itself and any other plugins or themes) can share the same id ("left" and "right" are already taken).
        'name'              => $LANG_GF20['blocks_showtopic_name'],
        'description'       => $LANG_GF20['blocks_showtopic_desc'],
        'template_name'     => 'forum_showtopic',
        'template_variable' => 'blocks_showtopic'
    );

    return $block_locations;
}

This function above gets called by PLG_getBlockLocations to find all custom block locations. This function also looks for any new theme specific block locations. See the example included in the Denim_Three theme as how to setup a custom blocks location for a theme (look for the theme_getBlockLocations_denim_three function).

To have a block display in a custom blocks location (that have already been setup by the plugin and/or theme developer) all you need to do is then edit or add a new block in the Geeklog Block Editor and pick the position you want. The new block locations automatically get added to the block positions. If a position becomes unavailable (either due to a plugin being uninstalled/disabled or a theme change) then the block automatically gets moved to the none position.

Custom block locations can also use the built in block header and footer template files. For example with the forum if you wanted to create custom block headers and footer you would have to create new template files called

blockheader-forum_showtopic.thtml
blockfooter-forum_showtopic.thtml

and store them in the appropriate theme location (this can include with the plugin own template files or with the themes). If these files do not exist then the default block header and footer are used.

eSilverStrike added a commit that referenced this issue Mar 13, 2018
eSilverStrike added a commit that referenced this issue Mar 13, 2018
…Footer stored directly with their template files

For Feature #707
@eSilverStrike
Copy link
Member Author

eSilverStrike commented Mar 13, 2018

@dengenxp @mystralkk Okay the functionality of this looks to be finished but it should be tested by others as well. I've added a blocks location to the forum plugin (which displays blocks every x number of forum posts). Ideally this could be used for someone wanting to insert info like advertisements every so often.

I could maybe add something like the forum blocks location for articles...
UPDATE - Okay I added this in for Articles. 2 locations include Article Footer (for regular articles not Archived or Featured) and Article Topic Lists. There is a config option for this as well to set it to display every x number of articles

@dengenxp Not sure if you want to add any extra blocks locations to one or more of your themes (like for example in the footer)... the option is there for you to do so if you wish.

eSilverStrike added a commit that referenced this issue Mar 14, 2018
Issues dealing with caching and defining what type of block locations. For Featue #707
eSilverStrike added a commit that referenced this issue Mar 14, 2018
eSilverStrike added a commit that referenced this issue Apr 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant