Try to mix CCK, 'Contemplate', Views and Insert Views modules.

I trying to create a custom CCK node that, put simply, consists of

***************
TEXT
------------
List of teasers[of a different [cck] node type].
***************

For a "once-off" page, I can create a view, that takes the node id as an argument, and generate a table view of the fields I want. This functions nicely as a teaser.

[A 'list' view doesn't seem to use the 'teasers' generated by Contemplate module, that's a seperate issue I think]

Given this view, I can create a page, using the 'Insert view' tags.

***********
TEXT
----------
[view:myview=1=10]
[view:myview=1=11]
[view:myview=1=15]
***********

And this creates the page I want.

However, I need to do this automatically.

Using CCK, I can use nodereference to reference the node I want to display as a teaser.
Using Contemplate, I can output this as a node id [nid].

But somehow, I need a way to 'process' this nid, by passing it to the custom view I created to output a teaser.

So there's the question at last!
How can I 'process' that nid?

I tried putting the 'insert view' tags in the Contemplate area, but it doesn't recognise them, and just outputs them as ordinary text.

Regards
Alan

Comments

maybourne’s picture

The nodereference will only give you a nid and I think the title of the node. To load the node (for the teaser/body) you need to pass the nid to the function node_load. You can find out more about node_load on the drupal api page.

- China Business News & Observer -

alanburke’s picture

Thanks for the reply maybourne.

[I'll just mention here that I'm not much of a coder, more of a hacker at this sort of stuff, but I can sometimes figure it out!]

I figured node_load would be the way to go. I tried hacking nodereference.module to see if I could get it to spit out the teaser, but I ran into trouble.

It seems that the teaser generated by contemplate module isn't actually loaded by node_load, as far as I could tell, and when I try to output $teaser, I get nothing.
[I managed to get some of the other stuff in the array generated by node_load to print out, such as node type etc]

This could be because the node_type is a CCK type.
While I was doing some work with Views, It seemed that generating a list of teasers of a CCK node wouldn't work either...

Thats why I created the View I mentioned earlier: If I can pass the node_id to this view, I'll get the output I want.

Since I wrote the initial post, I have come a little way.

By looking at the code for the Insert_view module, I see that there is a function in the views module that does the trick for me.

If I can pass the nid I get from nodereference to views_get_view, I reckon it will work.

But I wouldn't quite know how to do this?

Where would the code to do this go?

All help appreciated!

Thanks
Alan

alanburke’s picture

Getting closer.

From doing some more research, I can put this function views_build_view into my template file for the content type [or via contemplate].

I found this here http://drupal.org/node/47417.

However, I ran into the same problem as the last poster on that thread.
Try as I might, I still get the error

Only variables can be passed by reference in C:\drupal\themes\CONTRIB\clementine\node-content-golf_course.tpl.php on line 38
>/code>

Any suggested on how to call the view while avoiding this error?

Alan

Ian Ward’s picture

Hi Alan,

Maybe you're nesting a views_get_view inside your views_build_view like this:

$limit = 5;
$args = arg(1);
$type = 'block';
$output = views_build_view($type, views_get_view('viewname'), array($args), FALSE, $limit);
// see views_get_view('vewname')
return $output;

If this is the case, try pulling it out, defining it in a variable, and then using the variable like this:

$limit = 5;
$args = arg(1);
$view = views_get_view('viewname'); // turn it into a variable here
$type = 'block';

$output = views_build_view($type, $view, array($args), FALSE, $limit);
// $view is the views_get_view('viewname')

return $output;

Hopefully this helps. Your version of PHP may determine whether or not you can do the first one.

Ian

Development Seed Blog

alanburke’s picture

I had actually managed to do this a while back, in the exact same manner.
[ but I figured it wasn't good coding practice, it really felt like a bad hack, I don't know why!]

Shame on me for not posting my results anyway, given that it does work...

Thanks Ian,
Alan

Ian Ward’s picture

Just noting, there is now the http://drupal.org/project/viewfield module which helps w/ showing a view in a cck node type.

Development Seed Blog