Love the module. My use case is to take programatically take the result of a view and load it into a colorbox. I can use views_get_view or views_embed_view to get a result array or a large html string. But how can I pass that to the colorbox?

Your help is greatly appreciated.

Comments

Sam152’s picture

Status: Active » Closed (fixed)

Put your view into a div with a _wrapper_ that is hidden (ie, display:none;). Then you can use the following javascript:

    $.colorbox({
        'inline' : true,
        'href' : $('.views-view-my-view'),
    });

You must replace the 'href' attribute with the appropriate jQuery collection representing your view. Other customisations to the way your colorbox appears can be found on the colorbox website.

If you need some advice on placing a view on your page, here is a clean implementation:

    function MODULE_preprocess_page(&$vars) {
      $vars['page']['bottom']['my_view'] = array(
        '#type' => 'container',
        '#attributes' => array(
          'id' => 'my-view-container',
        ),
        'children' => array(
          '#markup' => views_embed_view(...),
        ),
      );
    }

In this case your selector for colorbox would be `#my-view-container .view`.

Source.

drtrueblue’s picture

Fantastic! Thank you so much. Prior to reading #1, I was able to use the inline approach successfully, however, I relied on a far uglier approach to getting the view on the page. The function was extremely valuable.

drtrueblue’s picture

Issue summary: View changes

adding views_embed_view as a possible function that can offer context to a possible solution