5

I have a view which displays all content of type "news" which is tagged with a specific tag, e.g. "world" (passed as parameter to the view).

The view machine name is news. It has a display of type Content Pane (machine name panel_pane_1). It also has a contextual filter set to "field_tags".

How to render this view content pane programmatically, passing tag value "world" to it?

(I've found ctools_content_render but no idea if this is the right function for this task and how to use it)

4

You can use

views_embed_view

e.g

print views_embed_view('news', 'panel_pane_1', 'world');

Any additional parameters will be passed as arguments, i.e contextual filter values.

0

You can use views_content_views_panes_content_type_render(). Here is a detailed example:

  // Important to include target content type.
  // You can also use 'views' content type but with a different render function.
  module_load_include('inc', 'views_content', 'plugins/content_types/views_panes');
  // Use your views machine name and display name here.
  $subtype = 'views_name-display_name';
  // Adjust settings to yours. You can debug ctools_content_render to see
  // all available settings in $conf. Or check
  // views_content_plugin_display_panel_pane::option_definition().
  $conf = array(
    'items_per_page' => 2,
    'offset' => 0,
    'more_link' => 1,
    'override_title' => 1,
    'override_title_heading' => 'blablalba',
    'override_title_text' => '',
    'pager_id' => 0,
    'use_pager' => 0,
  );
  // (optional) Prepare ctools context and context keys if your argument type
  // is 'context'. Check handling of other argument types in
  // views_content_views_panes_content_type_render().
  $conf['context'] = array('mycontext');
  $context = array(
    'mycontext' => ctools_context_create('node', $node),
  );
  // Render views pane.
  $pane = views_content_views_panes_content_type_render($subtype, $conf, $args, $context);

  // Get pane HTML.
  $output = render($pane->content);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.