Hi,
I created facet api block and I want to theme it (not only css, I want to add some divs, classes, etc)

I'm trying to invoke the block in other template, but without success.

There aren't default template for this block, that I would be able to override.

There aren't any hook function for this.

Any suggestions?
Thank you in advance :) .

Edit:
Also a way to render facet api block programmatically, by invoking the hook_block_view() in the module would be awesome!

CommentFileSizeAuthor
#6 Selection_013.png18.63 KBletrollpoilu

Comments

aripopova created an issue. See original summary.

abh.ai’s picture

I'm facing this same issue. I'm trying to render a facet api block programmaticaly. For some reason it isn't working like other regular blocks.
`$block = block_load('facetapi', 'H8t5HB0FXQR0lyo2OdJ6i9pqGROuNg6r');` works like every other block, but
`$render_array = _block_get_renderable_array(_block_render_blocks(array($block)));` returns an array with one element i.e., `#sorted => TRUE`
facetapi_block_view('delta') also returns 'null'

abh.ai’s picture

Issue summary: View changes
PiersShepherd’s picture

Im experiencing the exact same output as @abhaisasidharan.

This would be useful as I prefer to control block visibility in my templates and not in the block management system/context/etc.

PiersShepherd’s picture

After more testing and setup I managed to get a facetapi block to render using:

$block = block_load('facetapi', 'H8t5HB0FXQR0lyo2OdJ6i9pqGROuNg6r');
$render_array = _block_get_renderable_array(_block_render_blocks(array($block)));

The reason I was seeing only seeing #sorted => TRUE before was that my facet block was set to hide under certain situations:

- Hide items that do not change search result.
- Hide if no search is performed.

Once these options were unticked in the visibility settings for the facetapi block then it showed :)

So if anyone finds this page and is trying to render a facetapi block programmatically and it's not showing, you may need to disable some of the 'do not show' options in the block visibility config.

letrollpoilu’s picture

StatusFileSize
new18.63 KB

Dear PiersShepherd,

Thanks a lot for that post, it has proven very helpful. Somehow there are no good examples of including facets with PHP anywhere else.

I'm still having the issue where the facet only render "Sort".

So I looked in the block configuration, but it all looks good to me, I don't see the options you are mentioning.

letrollpoilu’s picture

Ok I found out, for me the issue is that I was calling the factet block before generating the index. Here is my code:

<?php
/* * ************************************ */
/* set news index */
/* * ************************************ */

function maintheme_init_all_news_teaser() {

    if ($GLOBALS['news_index'] === "") {
        $GLOBALS['news_index'] = views_get_view('news_index');
        $GLOBALS['news_index']->execute_display('panel_pane_1');
    }
}

/* * ************************************ */
/* get all news */
/* * ************************************ */

function maintheme_get_all_news_teaser() {
    maintheme_init_all_news_teaser();

    print $GLOBALS['news_index']->preview();
}

/* * ************************************ */
/* get date facet */
/* * ************************************ */

function maintheme_get_date_facet() {
    maintheme_init_all_news_teaser();
    $GLOBALS['news_index']->preview();

    $block = block_load('facetapi', 'A7drzElFYnYJtCeyg6YuCByfOxdQFlD3');
    $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
    print render($render_array);
}
?>