Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a computed field and i want to output a View's - block display with arguments passed into it. Can someone provide me with an example code of how to output a view with arguments?

thanks!

share|improve this question
actually i just realized that you cannot do this as a computed field is mainly used for storing data and since a views render would be dynamic, it would not work. a computed field only fires when you save your node. – duckx Jun 6 at 18:44
There are 2 ways for computed fields - stored and dynamic. You just don't want to store it. – Mołot Jun 7 at 8:49
your correct... there is a check box to make the field into a dynamic field. – duckx Jun 7 at 22:58

1 Answer

The long way:

$args = array(ARGUMENTS);
$view = views_get_view('VIEWNAME');
print $view->preview('block_1', $args);

The short way:

print views_embed_view('my_view', 'block_1', $arg1, $arg2);

This site helped alot: http://mydrupalblog.lhmdesign.com/embed-drupal-views-using-php

Also keep in mind since this is dynamic data, you will need to uncheck the checkbox on the field settings page or else it will try to store the data thats generated upon saving the node.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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