3

This is a follow-up to this question about automatic node title generation.

I'm using the "Question of the Week" content type. Its fields are "Date," and "Answer;" "Question" is its title.

What I want is a view with a collapsible field for "Answer." The view is used in a block shown in the front page ("This week's questions"), and on a page ("Past questions").

How can I get a view that has a collapsable field?

  • Automatic Node Title doesn't work the way I want it (can't hide hours, Doesn't update title when content is changed, etc)
  • View Accordion won't let me hide last of three fields (so I can't show two fields, "Date," and "Question," while hiding answers with VA).
  • Collapsable Text plugin screams about depreciated functions and breaks other stuff.
  • I don't see how to combine two fields into one in Views.

I either need to be able to collapse/hide a single field within a view, or combine two fields into one for the view. I'm looking "Computed field" now; I am not sure how to create a field via PHP, though.

I'm trying to make this into a computed field that adds the two fields together, "Date" and "Question," but all the examples I can find are Drupal 6.

1

To merge fields you should override a template in your view. ( Views 3 and HTML5 - how to override output for markup? )

I'm new to theming in drupal and wanted to merge fields myself to make collapsible fields few days ago as well, but with no luck. Then I used a css-only workaround without merging fields or modifying any markup. I used it recently in a comision work:

http://aelasoca.cat/web/

The frontpage is an unformatted view using fields. Each 'new' has the standard separate fields in separate divs (Title, image, date, intro-text, category). I used relative/absolute css positioning and opacity to show/hide text and put it over the image. Then with :hover behaviors and changing opacities and positions again I can make appear or dissapear fields. I've used this as reference:

http://www.sohtanaka.com/web-design/css-on-hover-image-captions/

  • What I ended up doing... was making a "computed field" using PHP to get a formatted "date" + "Question". Leaving my view to only pickup two fields: Date + Question... and answer... Which Views Accordion handles adequately. I'll post it as an answer so maybe you can see what I did... and I'll look at yours and see if maybe it's a better answer. – WernerCD May 17 '11 at 14:36
1

What I ended up doing...

I have 3 fields in the "content type: Question of the Week":

Date (Date of Question)
Question (Question of the week)  
Answer (Answer, needs to be "hidden" and shown on click)  

The problem was that Views Accordion would NOT hide two fields at once and I couldn't get views to combine two fields.

I found "computed_field". Using computed field, I made a field with this "Computed Code":

$timestamp = mktime(0, 0, 0, 
     substr($entity->field_jcqotw_date[LANGUAGE_NONE][0]['value'], 5, 2),
     substr($entity->field_jcqotw_date[LANGUAGE_NONE][0]['value'], 8, 2),
     substr($entity->field_jcqotw_date[LANGUAGE_NONE][0]['value'], 0, 4));
$formatted = date("M-d-Y", $timestamp);

$entity_field[0]['value'] = $formatted . '<br />' . $entity->title;

And this "Display Code":

$display_output = $entity_field_item['value'];

I have PHP 5.3 installed on my server and need to look at possibly using DateTime instead of Date... but this works for my means as of right now. It gives me date/time for

0

There is also a setting in Views to "rewrite" fields, which you can use to combine content in several fields into one. Open a field setting and check out the "rewrite" options. In particular, check out the "rewrite the output of this field" option, and the replacement patterns you can use.

Some more info is found here: http://drupal.org/node/1578524

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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