The feature of this module is just what I wanted, thank you for the great work!
According to my understanding of your module description, there can be only one view to be used as display of referenced nodes, since the view has to be named exactly as the field. So what can I do if I'd like to have different display for teaser and full node mode?
For example, I have a gallery content type with a node reference field "field_images" to contain images of the gallery so that each gallery can have multiple images. I wish to display only thumbnails for gallery teasers but show large images for a full node. Is it possible to do that?
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 475492.nodereference_views.teaser-view.patch | 956 bytes | joachim |
| #3 | teaser_and_full.patch | 2.18 KB | mianwo |
Comments
Comment #1
joachim commentedThis isn't possible I'm afraid.
CCK doesn't allow options for formatters, and the theme function doesn't have any data beyond the field contents, so there's no way for the theme function to know which node type it's being shown on or whether it's a teaser.
Have you looked at image module's galleries by the way?
Comment #2
mianwo commentedHow about creating 2 more field formatters in addition to the existing "View", one with the name "View for teaser" and one with "View for full node". And they look for view named "[field_name]_teaser" and "[field_name]_full" respectively. So user can choose which mode it uses for different mode in the field display setting.
There are indeed many gallery modules out there, many of them are actually using CCK and views to do the job. So I think it is possible to use CCK, imagefield and views alone, and this way I could have more flexibility and control over the final result. I prefer to install as few modules as possible to avoid future compatibility problems.
Comment #3
mianwo commentedI implemented the concept I just described, and it works!
Here is the patch, hope you don't mind I messed a little bit on your code. :D
Comment #4
joachim commentedHmm... yeah that's one way to do it but my gut feeling is that it's already a bit ugly having to match the view name to the field name, and this makes it uglier.
But on the other hand, I do see there is a case to distinguish teaser and full nodes.
So let's go with this -- but I am a bit wary of this being the slippery slope to then having view name suffixes for node type and it just getting more and more complex.
Why not have only two cases though, FIELDNAME and FIELDNAME_teaser? When might you need all three?
Comment #5
mianwo commentedI agree, 2 is enough.
I think a more appropriate way would be selecting existing views in the "field display" setting page. But letting user select views that are not designed for the content doesn't make sense too. No matter what, the user will have to create a view for the field, so current solution of naming convention is fine with me.
Comment #6
Firetracker commentedHi,
Is this being rolled out into a release?
Cheers
Zap
Comment #7
joachim commentedThe patch needs work as detailed above.
I haven't had time to get round to this yet, but if anyone else feels like having a go at it, please bear in mind the following minor coding style points:
- return theme_nodereference_views_formatter_views($element,'_teaser') -- don't include the underscore in the mode string.
- space after function argument comma
- space either side of string concatenation
Comment #8
looplog commentedFantastic module. I actually have a use case for three formatters, and that is, one for using the formatter for views (a view containing nodereferences formatted as views) as well as formatters for full node and teaser.
This is just a suggestion, but is it not possible to have a single default view named as per the nodereference field, and then have your module use views displays somehow to create any number of arbitrary formatters with the display name appended to the default?
Like i say, I don't really know views code well enough to know if this is possible, and I'm sure if it were possible this would involve a great deal more work, but it seems like from a user perspective to be an elegant solution.
Comment #9
joachim commentedGood idea!
That would save setting up multiple views too.
(Though for a formatter for views -- you can just use a noderef relationship in your main view and skip this module entirely.)
Comment #10
looplog commentedAhh, so that's what relationships are for!
One more idea and then I'll go to. Another solution would be to place an "add view formatter" link in the operations column for the nodereference in question on the manage fields CCK page. Click on the link, get taken to a view ceation page, enter any name you like for the view and the association can get made programatically on view submit. This would allow for any number of views and any number of formatters within the natural workflow of the field creation. Either that, or add such a link somewhere on the configure field page.
That being said, I won't be implementing any of this myself anytime soon. So thanks in advance for whatever additions are made...
Comment #11
joachim commentedHere's rough work at getting it to automatically switch if there is a display on the view called 'teaser'.
It doesn't work because as far as I can tell, there is nothing in the passed in $element that indicates whether we're in teaser mode.
Which means we may have to go to having 2 CCK formatters defined. I do still like having the system of having one view for both and using displays.
Posting this work so far anyway, but I don't expect to have more time for this feature in the near future.
Comment #12
joachim commentedNote to self: see the other issue where we discuss using displays the same way Views Attach does, and see http://drupalcode.org/project/custom_formatters.git/blob/refs/heads/6.x-... for an example of how to do a flexible number of CCK formatters.
Comment #13
joachim commentedThis is now doable with version 2, available at http://drupal.org/project/reference_views
Comment #14
joachim commentedI guess technically I fixed it... :)