I've installed insert view module and can insert views into drupal body but not into custom cck fields.

I've read here that this is not doable at this time but at another topic http://drupal.org/node/109293 there is mention that this is fixed in 5? I don't think so because I'm using 5.x and the latest version of this module and using [view:viewname] doesn't display the view just the text [view:viewname]. Unless what is fixed is something else?

Thanks for the clarification.

Comments

lias’s picture

FYI the way to add view with php and without insert_view is listed in the handbooks page: http://drupal.org/node/47417

$view_name = 'MyViewName'; //name of view
$limit = 3; // number of returns
$view_args = array();
$view = views_get_view($view_name);
print views_build_view('embed', $view, $view_args, FALSE, $limit);
mlsamuelson’s picture

Status: Active » Fixed

lsabug,

It is indeed possible to insert a view into a CCK field. In my test site, I just inserted the tracker view into a CCK text field.

The snippet you mentioned can come in handy when pager issues crop up with inserted views.

mlsamuelson

lias’s picture

Thanks for the confirmation on the snippet.

Is there any plan to have insert view work with cck?

mlsamuelson’s picture

Status: Fixed » Active

My testing indicates that it does work within CCK text fields in Drupal 5.

I don't think I tried the title field, but with the filtering on that field, it probably won't work (nor can I think of an implementation where you'd really want it to).

What version of CCK are you using? What field types have you tried inserting into?

lias’s picture

I had created a cck "content" field to replace the default "body" field. I found that whenever I removed the "body" from a content type insert_view would no longer work. It seems to need the drupal's body filter. I've tried this on two different 5.2 installations, one on Windows/Apache and one on Linux/Apache and both do the same thing.

As a workaround I created a separate content type with the default "body" field just so I could insert a view. It works okay, I"m using it with OG so that certain types of content are posted on specific group pages.

mlsamuelson’s picture

Okay, so what's probably happening is that hook_nodeapi() isn't triggered when you're not displaying the body... and nook_nodeapi() is where Insert View's magic happens.

I'll look into this further as time allows.

Thanks for the detailed description of the problem, lsabug!

mlsamuelson

erikhopp’s picture

Hi.

I'm having the exact same problem.

I've done something like this in a content type template:

$body = $node->content['body']['#value'];
print $body;

I've confirmed that when doing this:

$body = $node->content['body']['#value'];
print $body;
print $content;

it works.

But I don't want all the fields to print, thus only called my custom $body.

Is there a way to fire the node_api hook through template.php for a specific content type?

Thanks!

Erik.

erikhopp’s picture

StatusFileSize
new584 bytes

So, this is probably not finalized code that should go inthe module, but I think I have a fix that is pretty easy.

The following patch is attached:

--- insert_view.module (saved version)
+++ (current document)
@@ -46,6 +46,8 @@
   if ($op == 'alter' && function_exists('views_build_view')) {
       $node->teaser = _insert_view_substitute_tags($node, 'teaser');
       $node->body = _insert_view_substitute_tags($node, 'body');
+			$node->bodyvalue = $node->content['body']['#value'];
+			$node->content['body']['#value'] = _insert_view_substitute_tags($node, 'bodyvalue');
   }
   elseif ($op == 'print' && function_exists('views_build_view')) {
     $node->content['body']['#value'] = _insert_view_substitute_tags($node, 'body');
mlsamuelson’s picture

Category: support » feature

I've done some testing today. I was able to insert a view despite turning off the body on a custom CCK content type - but I think I've determined what must be going wrong... thanks in large part to erikhopp's patch which illuminated the problem, though doesn't solve it in a larger sense.

The issue, I surmise, arises from individuals printing out non-standard theme variables in their node.tpl.php files. Not all of these variables are affected by the insert_view_nodeapi() function which is used to do the Insert View magic.

In node.tpl.php, insert view tags work when printing out: $content or $node->body

You'll only see the [view:viewname] tag with these:$node->content['body']['#value'] or a CCK field like $node->content['field_custom']['#value']

Not very helpful if what you want is to use Insert View and trick out your theme at the same time.

My feeling is that Insert View should stay simple, at this point, however, and not start second guessing other processes in Drupal.

I'm very open to other's thoughts and ideas, however...

mlsamuelson’s picture

Side note: I forgot to point out to folks that you have to be very careful when printing out non-standards variables in your themes, as when you use the non-standard variables, you become responsible for sanitizing the content. In that case, filter_xss() is you friend. See http://api.drupal.org/api/function/filter_xss/5 .

(Just wanted to share that since it's a matter of security. Let's not have this issue queue become a thread on this topic, though. Let's stick with the issue.)

tommo’s picture

With reference to Isabug's first comment (#1) - I think there may be an issue when trying to use this code in a cck tpl file as in this cas: http://drupal.org/node/192655 .

Any thoughts?
Tom

mlsamuelson’s picture

Status: Active » Fixed

Using Insert View tags in cck fields should now work as long as the field uses an input format associated with it. For the solution, see recently committed patches http://drupal.org/node/224987 and http://drupal.org/node/180042. They make Insert View a true filter module (ie. it now does its work via hook_filter() rather than hook_nodeapi()).

Currently the updates are in HEAD and the D5 branch, but I'm planning to make an actual release before long.

I'm marking this issue as fixed. But please open it up again if you experience any issues.

mlsamuelson

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

arnaldex’s picture

Hi there,

I'm using the CCK "Computed field", instead of use this line:

print views_build_view('embed', $view, $view_args, FALSE, $limit);

I use this one:

$node_field[0]['value'] = views_build_view('embed', $view, $view_args, FALSE, $limit);

and everything is fine! (without the PHP tags, of course).