Theming

cbroberts26 - May 19, 2009 - 17:12
Project:Views Custom Field
Version:6.x-1.0
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

The problem is probably that I'm assuming this module does something that it wasn't designed to do, but it would really help if you could write a couple of sentences explaining just exactly how this works.

I've installed the module and activated it. Isn't something supposed to happen now? I guess I expected to see some new options in the Views workflow. Specifically, I was hoping that the Fields I selected for display would have input options that allowed me to enter additonal PHP or HTML and thus alter what is generated for display by the view.

But I don't see anything different in my Views interface. Can you clarify how this works? Is there some additional configuration I need to do?

#1

cbroberts26 - May 19, 2009 - 19:25
Status:active» closed

Ok, I think I get it now. As I suspected, the problem was that I was expecting something different from what the module provides.

The custom fields appear on the list of Fields to add to your view. They are not added as new input options for existing Fields. You can create a new, custom Field and put your PHP code in it, but you can't take an existing Field, like Node:Teaser, and throw in some PHP code to modify what is displayed.

Or can you? Ah ha! If you add the custom PHP field after, say, the teaser field, then set the teaser field not to display, you can grab the teaser text from the SQL results using $data->node_revisions_teaser and embed the teaser text in your PHP and go to town! Great! This works a little differently than I expected, but it does what I need.

For anyone struggling as I was:

1. When creating a view and adding Fields to the view, the Fields available will include custom fields like Customfield: PHP Code. Add one of these fields after you've added the regular content fields like Node:Teaser (if you want to modify the way the teaser text is displayed by embedding PHP in the view output).

2. Set the Node:Teaser field to Exclude from Display if you want to display the teaser text only in the custom field where it is modified with PHP code (or HTML code if using Customfield: Markup).

3. To grab the teaser text and display it in the custom field, use $data->node_revisions_teaser in your PHP code. So it would look something like this:

<?php
    
echo "This is the teaser text from the database: ".$data->node_revisions_teaser;
?>

You can see what data is being returned from the SQL query and what the variables are being named by looking at the SQL string displayed at the bottom of the Views > Edit page after you've updated after adding a Field. You'll see variable names like node_title and node_created depending on what fields you added to the view.

And now I imagine you can do almost anything to the display.

Obviously most of you understood all of this from the beginning and didn't need anybody to spell it out, but I assume I'm not the only one struggling to figure out how all of this Drupal stuff fits together while still trying to meet deadlines. Hopefully some will find this helpful.

#2

whan - August 27, 2009 - 15:28

Thanks, the information helped me a lot.

#3

rashad612 - September 17, 2009 - 08:10
Title:Could you provide a little more information?» Theming

How can I override the Views Custom Field in tpl page ?

#4

kevin riggen - September 21, 2009 - 22:58

To find out what fields are accessible you can use:

<?php
print var_export($data, TRUE);
?>

#5

ecksley - September 27, 2009 - 04:35
Version:6.x-1.x-dev» 5.x-1.x-dev

Great module!

I wanted to use it as a means to strip the "The" from the front of some node titles so that my Views page can sort them alphabetically without it.

However, I don't see a way that a View Custom field can be used as a sort criteria? Is that correct?

#6

kevin riggen - October 10, 2009 - 04:06

#7

Polo - October 14, 2009 - 20:29

You are my savior!

#8

nadav - November 9, 2009 - 17:52

hello :)

First of all, like all the others, but still, in a very spacial way, thank you for this amazing module, I just found it and I'm thrilled about it. So thank you!

I'm working on this view now that has three fields as grouping field and I'm using Custom Field for merging them to the same field. First two are text fields and work very good,
the third field is image_field and for some reason it is not showing. I am not so good with php yet (and I wonder if this is why it's not working.. hmm ;) ).
this is my code

<img src="<?php
echo $data->node_data_field_image_cache_field_image_cache_fid?>
"/>

this is the fields information that I get:

stdClass::__set_state(array( 'nid' => '1', 'node_type' => 'product', 'node_vid' => '1', 'users_name' => 'admin', 'term_data_description' => 'description text', 'term_image_tid' => '1', 'term_data_name' => 'name text', 'term_data_vid' => '1', 'term_data_tid' => '1', 'node_data_field_image_cache_field_image_cache_fid' => array ( 0 => array ( 'fid' => '3', 'list' => '1', 'data' => 'a:10:{s:3:"alt";s:0:"";s:5:"title";s:0:"";s:8:"duration";i:0;s:6:"height";i:22;s:5:"width";i:35;s:18:"audio_bitrate_mode";s:0:"";s:18:"audio_channel_mode";s:0:"";s:12:"audio_format";s:0:"";s:13:"audio_bitrate";i:0;s:17:"audio_sample_rate";i:0;}', ), ), ))

thank you upfront :)

#9

jcroft - November 17, 2009 - 22:06
Version:5.x-1.x-dev» 6.x-1.0

This worked for me.
Note in my case the cck field was named "image_1"

<?php
$file
= field_file_load($data->node_data_field_type_field_image_1_fid);
$imgPath = $file['filepath'];
echo
"$imgPath";
?>

#10

colemanw - January 2, 2010 - 16:41

Just wanted to say thanks for an invaluable little module. Using the custom php field you provided is the only way I have been able to include comments in a view of nodes with row-style: fields. Here's how I did it:

  1. Create a node view to show the nodes you want. Set row-style to fields, and include the fields you want. For my blog view, it shows nodes of type 'blog' and the title, author, headshot, and content fields.
  2. Create another view (not just another display, you need a whole extra view because this one is for comments). Name it comment_view or something. Give it the relationship "Comment: Node" and the argument "(node) Nid" and set the row style either to full comment (to show comments exactly like everywhere else in drupal) or create custom fields to your hearts desire.
  3. Go back to your node view, and add one more field, this time a custom PHP field provided by this module. Type in this php code:
    <?php
    print views_embed_view('comment_view', 'default', $data->nid);
    ?>
    Substitute the actual name of your comment view for 'comment_view' if you named it something else

And viola, you now have a display of both nodes and comments that is 100% customizable using the power of views.

PS. I was surprised there wasn't a more straightforward way to do this. If anyone knows of one, please feel free to enlighten me.

PPS. Of course, if you don't require the 'fields' row-style, there are many more options for achieving this, including just clicking the "show comments" box in views or (if you want to customize the comments, i.e. by limiting the number shown, fields, etc) doing step 2 above and then embedding that view in the template file of the node-type in question. You can get around having it show up in the actual node page by using the teaser view instead of the full view.

#11

benjah - January 6, 2010 - 00:54

#9 above worked like a charm!!!!
Thanks jcroft!

 
 

Drupal is a registered trademark of Dries Buytaert.