Friday, October 8, 2010

Embedding Drupal views, with PHP

If theming Drupal and want a view where it occasions output using a view representation (such as a page or a block are perhaps placed inside a user-defined region;-)) or insufficient views attach.

Instead, you can embed a view by using the following PHP code snippet:
(Note: you need the core PHP input filters that are enabled when a node body embed)

<>
$ View = views_get_view('VIEWNAME');
Print $ view-> preview('default');
?>

or, if you must use an argument with the view:

<>
$ Args = array(ARGUMENTS);
$ View = views_get_view('VIEWNAME');
Print $ view-> Preview ('Default', $ args);
?>

NOTE:

VIEWNAME with your actual view name - replace e.g. ' My_drupal_posts ' replace ARGUMENTS with the argument (s) that your view is expected - such as this may be a node-id

PHP snippets above issue, you can spend your 'Default' view anzuzeigen.Allerdings other displays from the view (if your view has multiple displays) - e.g. to output of a view first block display that would modify the snippet view by replacing the views of ID 'Default 'with' block_1' and use:

<>
$ Args = array(ARGUMENTS);
$ View = views_get_view('VIEWNAME');
Print $ view-> Preview ('block_1', $ args);
?>

View the original article here

No comments:

Post a Comment