开发者

Drupal: Re-using faceted search blocks

The faceted search module in Drupal creates a set of blocks for each new faceted search environment (current search, guided search, related, etc).

If you were to create a faceted search environment for e.g. books, you could set it开发者_StackOverflow中文版 up with a base path browse/books and a start page as browse/books/results. To display the faceted search blocks, you'd then set the Page Specific Visibility settings for the block as 'Show on only the listed pages' and the actual pages as

browse/books
browse/books/results*

Question: I would like to re-use the 'guided search' block on a different landing page. The landing page should display a list of available search terms (sidebar-left) and show a view over the rest of the page.

So far, simply adding a different path to the list of 'show on only the listed pages' has no effect.


One way of almost getting there is to add a new custom block and then trying to display the actual block using the following:

<?php
   $block = module_invoke('faceted_search_ui', 'block', 'view', 'xxxxx');
   print $block['content'];
?>

Where xxxxx is the id of the faceted search environment, for example 1_guided. Problem is that looking at function faceted_search_ui_block(...) will only get you so far. The block will only be rendered if the environment is in the correct state, which, unless it is a known faceted search environment supposedly running under the associated path, it is not.

So, doesn't look like it is possible.


Drupal veterans would likely be able to offer better, cleaner and more correct solutions, but the following works for me:

I added a new block which runs the following PHP:

$env = faceted_search_env_load ( $fs_env_id );
if (!$env->ready()) 
{
    $env->prepare();
    $env->execute();
}
faceted_search_ui_add_css();
$env->ui_state['stage'] = 'results';
print faceted_search_ui_guided_block($env);

$fs_env_id depends on your setup. The links generated by the API will link to the actual faceted search environment paths, as expected.


Hmm. I am not sure if this is what I was looking for or not-

Here is what I am using now. I don't know if it is exactly what your looking for but you can render the facets on any page that is applicable. (the facets are supposed to show on)

For me it is search results via views.

I am rendering a block, with all my search facets in one block.

<div class="xfacet">
Something here
<?php
$block = module_invoke('facetapi', 'block_view', 'xxxx');
print render($block['content']);
?>
</div>
<div class="xfacet">
Something there
<?php
$block = module_invoke('facetapi', 'block_view', 'xxxx');
print render($block['content']);
?>
</div>

I just control where the block shows.I'll follow up with a link after launch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜