By jeff h on
I've themed my view's "list view" with great success, based on the code automatically generated by the views_theme_wizard module. Unfortunately this module currently only provides code for list views and I would like to theme a table view.
Is it possible for someone to post some code that is relatively generic that I can modify to get me going? It would be much appreciated.
Thanks,
Jeff
Comments
Same question
Same question here....
Thanks for anyone who can help. I, and I assume Jeff, are beginners, and parsing the "Theming With Views" documentation can be a bit intimidating.
Have you tried CSS and theming individual fields?
Tell me more about what you're trying to do with the table view.
The views theme generator can generate a list of fields that you can theme with phptemplate, as well as phptemplate snippets for theming list views. If you are just looking to edit how these fields display in table views, this is a good option. You can also choose between changing the how these fields display in all tables views, or just specific table views.
Some examples are that you can use the date() function to change how date fields are displayed, truncate titles, etc. If you want to get really fancy, you can even use conditional statements within the the phptemplate field themes.
Another option for theming the overall table is just to use css classes. In the styles.css of your theme, you can change classes such as:
.views table
or
.view-specific_view table
A cool trick with table CSS that works with Firefox (but not IE6 of course) is styling the td:hover element to highlight cells when you mouseover them.
I'd be happy to try to help you come up with some snippets if you can give me a little more detail.
Cheers,
Sean
Sean Larkin
Thanks for the reply!
Thanks for the reply!
For my specific situation, I think CSS might do the trick, but I'm not sure.
I have an table that's being output by views. I would indeed like to format the whole table, rows, columns etc, but one of the problems I think might require a different repsonse.
One of my fields is a location field, that outputs the address and a link to the google map, but in a very ugly manner. I want to change the way this field is ouput.
Thanks for your help! It is very much appreciated.
A little more info if it is helpful: I'm runnin 4.7.3, with an altered bluemarine as my theme.
ouch
I haven't used maps in table views. What's the theme generator output for that field? Is this some sort of a teaser view generated by the gmap or location module? You might have to override a themable function in the mapping module. Do you need the map in the table view - or could you get away with just the link to the map in a separate node? You could use display:none in your css - but search engines doen't like that too much, from what I hear.
Good luck,
sean
Sean Larkin
Thanks for the reply, I
Thanks for the reply, I appreciate your time.
It's not outputting a map, just an address and a link to a map - it's generated by the location module. The address just looks really ugly - it's alignment is to the right, and it just doesn't look right. I just can't figure out where/how to change it.
Thanks again.
combining fields into one <td> of a table?
Do you know if it's possible to combine multiple fields into a single column in table view? I know that the "location_views.module" does this and provides a Location: address option to the views fields. But is this possible for CCK generated fields? Would there by some way to theme it in template.php? I am already theming the individual fields, but am unsure of how to combine two or more fields into one
Thanks!
combining fields...
I did it by overriding the entire theme_views_view_table function. I have a table view with date, location (actually a plain text field - I'm running 5.0-beta and location.module appears to not be quite ready), link, title, and body fields, which I wanted to display in a three-column table. The cells should be date, location, and details. The details column should contain the title (formatted as a link to the URL contained in the link field) and the body.
So in the foreach loop that puts together the fields in each row, I check the field name. Date and location are treated just like the original theme function - the value is put in a cell and the cell is added to the row. For the link field, the URL is saved in a variable without creating a new cell. Then the title field is formatted as a link to that URL (unless it's empty), and put in a cell. The cell is not added to the row yet. Finally, the body field gets appended to the cell, and the cell is added to the row.
I also have to generate my own table header, because left to its own devices the view would stick a five-column header on top of my three-column table.
Caveat: there may be a better way to do this. In fact, I found this question while trying to figure out if this was the best way. So, if someone has a simpler solution, I'd love to know about it. This way at least works, though. Here's my code; change 'mytheme' to your theme name, put it in your template.php, and work out how to plug your own fields and formatting needs into it.
Theming views tables
Thanks for the great snippet, it helped me a lot. I wish there were more tutorials and examples out there for theming table views.
Sort Icon?
This code helped me a lot! Thanks. How do I get the sort icon to show up? Since I'm not using the generic
return theme('table', $view->table_header, $rows);but instead am using
return theme('table', $header, $rows, array('class' => 'show-table'));and the $header is defined in the top part of the code...
When I use a generic template and don't try to combine fields, I have 5 columns and the sort button appears next to
. But when I combine two columns and use the header code above, I loose the ability to have the sort button appear. Ideas on how to get it back?
How to sort
I got the field sorting to work properly, as of 5-30-08, by doing this:
function phptemplate_views_view_table_YOUR-VIEW-NAME-HERE($view, $nodes, $type) {
foreach ($view->table_header as $field) {
$header[]=array('data'=>$field['data'],'field'=>$field['class']);
}
how?
Can you give me an advice, how to apply the field sorting code only for one field? I do not wish to overwrite the custom cell numbers, datas and classes. I'd like to change it for only one field.
only one field? you can add
only one field? you can add and remove the sorting right from the original view.
it only needs custom coding when you are altering the columns, like merging or removing columns.
if you need such customization, the table headers are in an array, in the same order of the cells.
also remember that column sorting may not work when there's regular views sorting.
adding the sorting link manually won't work if it is not already set in the view.
for example, you can hide the whole column of a date field but still show the header to sort by date.
Hopefully you might help me on Views
I created a table views. it shows an error message for anonymous user while it's working fine for authenticated users.
it gives this error message: » warning: Invalid argument supplied for foreach() in :\hshome\myname\modules\views\theme\views-view-table.tpl.php on line 22.
Even if I configured the block to be visible for both.
Thanks
I am also trying to combine
I am also trying to combine several fields per column in a total of 4 columns. I tried your code, tried to modify it, but I cant work it out :-( The formatting of the header part works. And I thought the name of my field goes in case 'field_name_value*. I dont get any output that way though. I only get output if I only name it case 'value'. Here's what I'm trying to do:
Go from my very wide table:
Last Name | First Name | Street Address | Zip | City | Phone 1 | Phone 2 | Fax | Mobile | Email 1 | Email 2To:
First Name Last Name | Street Address<br />Zip city | Phone 1<br />Phone 2<br />Fax<br />Mobile | Email 1<br />Email 2Is there anything I can do to get this kind of output? I've been looking at all posts about theming tables, tried all kinds of things with different code, but none is working out...
I'm still dealing with
I'm still dealing with theming the table view and could use some more guidance if a kind soul would be willing to help me.
I tried using this method of:
.views table
or
.view-specific_view table
and dropping it into my style.css but it didn't seem to make any difference. Is this because I need to edit my template.php as well? If so, I do not understand exactly how to do it.
I made changes to the way my style.css handled all tables, but since my theme is not table-less css based, it affected headers and everything else and made things real ugly.
Theming a Table View with CSS
Theming a Table View with CSS worked for me.
Change the following style sheet to suit then paste into your style sheet in your theme folder:
Source and more options: http://drupal.org/node/154087
css table gallery
http://icant.co.uk/csstablegallery/
You can apply some css table design from that web site
Just Enjoy
---
Daily webmaster news and directory (digg style)
http://www.dwebmaster.com
placing images inside the fields?
I am using 4.7.2 and heavy on the tabled views.
what i want to do, is grab some text in the column, and swap it out with an image. for the link above, it would be something like having the country flag in place of the country name. my field is populated by a simple text field. not a taxonomy. is there a way to do this?
j
I too would like to know how to do this
I too would like to know how to do this.
Please keep in mind I'm a designer and a caveman programmer (take code, bash it with rock until it works or is dead) :)
Specifically, how to change the picture field to sub out the thumbnail with a standard icon.
override the table function
Try overriding one of the theme functions. Below is code similar to that previously posted but more generic. Put this in your template.php (replace "mytheme" with the name of your theme). You can format the data as you like using tables ... this will just make the data accessible.
Thanks for the tip - I'll
Thanks for the tip - I'll try that out.
url and image
I have created a cck type with a url (named 'url') and an image field (named 'image'). I want now to display a table of images in a view (named 'myview'), and when you click on one of the images, I want the user to go to the url.
How can I theme the table rows of myview so that I can insert the image into the url?
Also, if the function isn't
Also, if the function isn't called right away, try calling it by engine:
function phptemplate_views_view_table_TABLENAME($view, $nodes, $type) {}
Apart of the newer tpl filenames, you can still put those in the template.php of the theme (or include from it).
Same link Question
Hi inforeto,
same link question i themed my view an i want to have a certain field al link something like this:
case 'field_bildchen2_fid':
$cell['data'] .= 'div class="view-field-'.$field['queryname'].'">';
$cell['data'] .= 'a herf="/dirksway/user' .arg(1). '/galerie'. '">';
$cell['data'] .= views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
$cell['data'] .= '/a>';
$cell['data'] .= '/div>';
break;
But i tryed 50 possibilities but nothing working. Any solution?
Dirk
PS I removed all < in the text.....
The code is right, but is
The code is right, but is the switch/case loading?
It usually goes inside the loop:
foreach ($view->field as $field) {}
What i do is counting the cells with something like:
Debug it a little and you'll get it working.
Otherwise post the whole function.
Use code tags to keep the > and < signs.
I will try...
Hi inforeto,
thanks i will try a bit...
Nope.....
Here comes my original function:
tryed your switch but i´m to dummy.
Dirk
Tell more! What do you got
Tell more! What do you got as results?
Is the data still showing up in the default way?
Is the table broken? Is the whole code broken?
Troubleshoot part by part.
Check if the code isn't being skipped:
switch ($field['field']) {}
(try printing the $field['field'] to see if 'field_bildchen2_fid' is there)
and
if ($fields[$field['id']]['visible'] !== FALSE) {}
(what is this btw? try removing it)
Then check if the rows are done properly:
Try:
(which i believe is how it works)
instead of:
No Link
HI Inforeto,
no the view is working, every thing is going the view displays correct but. Exept i´m not able to make a the field_bildchen2_fid a link.
I want to make it a link. I can do it bei using an other function phptemplate_views_handle_field_TABLENAME_FIELDNAME, but than i chage the properties of this field for every view. But i just need to change it for just this one particular view. I allready did it for the taxonomy-term displayed together with the view, but now the client wants it for the image as well..... And i´m stucked with it.
Here http://www.freelens.ws/dirksway/lutz-fischmann you can see the view in the third row of the profile page.
Maybe you have any idea....
Dirk
PS. if you have anything i can help you, just tell me. Just have a look at my site. I give you a username: Bernd Arnold password: test so just login
You still need to debug the
You still need to debug the function, to see where it skips your code.
Try printing comments or values for each cell, like:
And have you tried removing the
if ($fields[$field['id']]['visible'] !== FALSE) {}
?
I removed it
Hi inforeto,
I removed it tryed and tryed again but no result. i can print the field as textlink with a l() but no way to make the image a link. The field is there "field_bildchen2_fid".
?
Dirk
ok, but you are saying the
ok, but you are saying the function is running, right? so you can do things within the case:
Now, if you can add tags, what is the output of 'field_bildchen2_fid'?
(post the html output, for 'field_bildchen2_fid' only)
Also, what is your code for l() ?
(post the case for 'field_bildchen2_fid' only)
Is the anchor/link tag there but broken? If so, just check the html syntax.
But if it is not being print at all the code is not running. Check php syntax too, including commented lines.
html code for field_billdchen2_fid
Hi inforeto
This is the html code for my image
First a div
The div is TABELNAME_FIELDNAME node_data_field_bildchen2/_fiield_bildchen2_fid
For me this looks like a correct html_code, but the image/field_bildchen2_fid makes no action.
So i could not find any hint some where how to fix it.
Dirk
So there's modified output,
So there's modified output, meaning the php works.
html is correct, so now check for typos and css interferences.
(herf ? href)
<a href="dirksway/user/2/galerie">Now it´s working
Hi Inforeto,
thanks for the spelling tip. This was the problem.... Ok any help you need just send me an email.....
Good luck and warm regards from Cologne.
Dirk
PS: did you liked the site?
another option?
Hi Jeff h,
Just wondering if you are generating your views from cck.node types.
If you are I was going to suggest combining the fields by creating a new cck field using the Computed Field add-on for the CCK.MODULE. As I understand it, you can call other fields and combine them into that new field, so when you go to views, you can select that computed field.
Not sure if that makes sense or not, but, I was looking at views and thought that was one possible way of doing it (combine multiple fields into the same column table cell).
Dub
Edited; I tried this approach with no success, the COMPUTED FIELD module add on for CCK is useful for calculating but not joining fields together.
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
I too need help...
I've built a site that is currently live but one of the views I built displays in a table and the client doesn't like it. I can't blame him, the fields are too small and make the whole page ugly. You can see what it looks like by going here:
http://www.tarantulaspiders.com/view/catalog
What I'd really like is what you see here:
http://www.technospider.com/~david/views/
Basically, I want top row 2 columns 1 for title, the other for price. Middle row, spans both columns and is used for body. Bottom row, 1st column empty, 2nd column for Add to Cart/Sold out.
If anyone could help me out with the code and some good instructions I'd be grateful. I also only understand the hammer approach to working with code. I get a fever as soon as I type PHP... ack up to 101.1 already
Thanks,
David
http://www.floridapets.org
To modify the table itself
To modify the table itself you need a function just like when you need to modify the values.
See the examples above on how to do that.
In the examples, you'll see arrays named $cell, $row, $rows, $header, etc.
Those will store the values so you only need to pass $them to the theme() function that will automatically create the table for you.
You can find more about that in the handbooks or in the search results.
You need to play with it a little, which will be easy if you know php.
What i do is to store the values of each node in variables, and assemble the $cell and $row just before the node's loop end.
I don't know if rowspan or colspan attributes are added automatically, but if not, the proper way should appear in the handbook.
I don't...
I don't know PHP at all, that's why I was asking the fine people of this board for some help. What you said about arrays and such is meaningless to me. Not that I haven't tried, it's just that everyone has to be bad at something and coding languages is what I'm bad at.
Thanks,
David
http://www.floridapets.org
Unfortunately, there's no
Unfortunately, there's no easy gui tool yet to modify tables.
To create a table programatically you need to code the function that would do it.
But minimal php skills can get you there, if you spend a little time on reading the examples.
The idea is like this:
You need a table with the html tags: table, tr, td, etc.
The php code reads the node and puts the field values in $cell, which results in td tags.
The $cell is then put in $row, which results in tr tags.
The $row is then put in $rows, which results in table tags.
To modify the default table, which is a simple table, you need to alter the order in which the values are put in the variables, so that the table is created automatically.
Since you want a particular arrangement, you need to first to "design" where you want the values.
In your example, you have title, description, price and link, and want to group title and price above, then the rest below.
To do this, you need to supress the part of the sample code that deals with $cell and $row.
Instead, you put the values in variables, like $title, $price, $desc and $addtocart.
The sample code shows several ways to identify these values.
Once out of the loop write some code to replace the supressed parts and rebuild the arrays:
pass $title and $price to $cell, then $cell to $row, and $row to $rows, making one row,
then the same for $desc and $addtocart to put them in the second row.
In the end, if you keep the rest of the sample code, the table will be built automatically.
The $cell has a property for class, which is then used to apply the css style that will format the table.
Make your function and you can post it here for reviews.
Uh
I just read your reply, and now my brain is leaking out of my ear.
Thanks,
David
http://www.floridapets.org
See if tablemanager module
See if tablemanager module can help you: http://drupal.org/project/tablemanager
I don't know if it can pull data from views.
Deleted unrelated post
Deleted unrelated post (views_filterblock). Sorry
I know how you feel.
I know how you feel. Progammers/developers tend to create for other programmers/developers and not the actual majority of people (non-programmers/-developers) who actually create stuff. Drupal is still in that "geek/dork" phase and, until it learns to move past that and provide sophisticated ways of doing programmatical things (i.e. dumb it down but don't remove functionality), Drupal will remain a niche CMS. Who wants to code in script when a decent GUI is possible that can do most things? Leave the scripting for more hardcore/unusual/uncommon things that, really, only geeks/dorks'd be interested in doing.
Geek angst
Well, the majority of what most people need to do, I think can be done fairly easily with Drupal. Although I guess I consider myself somewhat of a geek/dork in your words. It's just anything that needs actual programming that I can't tackle, and I guess what I want to accomplish on those occasions probably isn't really a mainstream request.
Thanks,
David
http://www.floridapets.org
Each Field Appears In A New Row?
How would one modify the following code so that each field appeared in a new table row (instead of fields in adjacent cells within the same row)?
How did you solved this? A
How did you solved this? A have a similar the same problem, and nobody gives an answer.
I have made this table: I have 2 array's UGentArray and InternshipsArray.
How can I set these in my table? Instead of "Row column 1 data" and "Row column 2 data".
My question is: I want the values from UGentArray and InternshipArray as 2 columns under each title UGentID and Internships.
How would one modify the following code so that each field appeared in a new table row (instead of fields in adjacent cells within the same row)?
// Make table and display on screen.
$tbl_header = array();
$tbl_header[] = array("data" => "UGentID");
$tbl_header[] = array("data" => "Internships");
$tbl_row = array();
$tbl_rows[] = array();
foreach($studentUGentID as $key => $value) {
$tbl_row[] = $value[0]['value'];
}
//$tbl_row[] = "Row column 1 data";
$tbl_row[] = "Row column 2 data";
$tbl_rows = array();
$tbl_rows[] = $tbl_row;
$html = theme('table', $tbl_header, $tbl_rows);
return $html;
Merging cells in table view
I've read somewhere that $cell gives a < td >. Is it possible to merge cells in a row, like < td colspan="2" >?
Yes, you use
Yes, you use $cell['colspan'] = 2;
See http://api.drupal.org/api/function/theme_table/5
The $cell array can have attributes, altough the table builder it is also capable to the colspan automatically if columns don't match.
And if i want to call other variables??????
Hi i'm all stock
I have a content type that is also a product, and i created a view (table view) but only shows me the cck fields how do i display product variables on that table view??? like $price or $stock
You'll need php to load
You'll need php to load anything that the modules do not have available to use in views.
If those variables are available in the $node you can use node_load() inside the themed view.
In this way you just manually add those values into $cell and the table will be built automatically.
How i do that? Sorry
i don know much of php i guess that i have to alter the template.php but don't know how exactly
can u point me to an example.
gee sorry for the trouble. and thanks for the help.
Search for "Theme Views",
Search for "Theme Views", and read the book pages.
Like http://drupal.org/node/42597
The examples in this thread are also good, and others on the same topic.
You can pick one as the barebones where you do the modifications
(the function usually goes in the template.php file).
Use a test site to try the code, or open a new thread for specific support.
tracking
tracking thread
Hello All, i am trying to
Hello All,
i am trying to customize the table view in a way that fields will be listed verticaly.
i have 18 cck fields + 1 imagefield
i want to list 3-4 nodes in a table looking something like this
|node1 | node 2 | node 3
label1 | node1filed1 | node2field 1 | node3field 1
label2 | node1filed2 | node2field 2 | node3field 2
etc..
unfortunately the above code examples look a little chinese to me.
can someone give me a simple example that can get me started?
thank you and sorry for the trouble
I just can't believe there
I just can't believe there is no GUI for this sort of thing. I can't follow any of the code snippets left above...
Why can't it by like creating fields for a content type where you group fields so they get grouped in the /node/add/xx page?
I envision that you should be able to make "field groups" in a View creation and drop fields into those groups for table views.
Sounds like a great module.... :)
I have two fields that I want stacked in one column on a table view...what code would I put in what file?
view name = '36'
field names are: field_1 & field_2
theme is just 'bluemarine'
thx for any help you can give
Combine two cells
I've been able to combine insert colspan="2" but have not been able to combine the data from two cells. Help please...
Thank you.
Head of Library Technology Initiatives and Development
California State University San Marcos
http://biblio.csusm.edu/
Simple way to handle alignment
I have a views table built from a CCK content type and all I want to do is align the cells with currency to the right. Is this possible?
Alignment is best done via
Alignment is best done via CSS.
The use of php is generally to edit the actual values.
re: Combine two cells
To combine two cells, I've created a computed CCK field which concatenates the two cell values, then used the new computed field in my view.
Amnon
-
Professional: Drupal Israel | Drupal Development & Consulting
Personal: Hitech Dolphin: Regain Simple Joy :)
Just check Computed CCK Field
Just check Computed CCK Field. But I am not sure how it can solve the issue mentioned above. Just wish more information.
can u paste your code?
can you paste your code levavie that you used to concatanate the two cells?
I'm looking for an example I can try out.
subscribing
subscribing
Can anyone help me with this output?
Hey guys, I have those lyrics here:
http://www.alizee-fanpage.com/lyrics
I dont like the default way of them being displayed. I tried with drupal theme wizard but i didnt get a good result.
What I want is the nodes to be displayed this way, grouped by album in a table view like this:
Album (1)
Song name (1) Track ( ger | en | es ... ) All available languages as language flags and link to the node
Album (2)
Song name (1) Track ( ger | en | es ... ) All available languages as language flags and link to the node
--
Check out my blog
http://blog.riccardo-ulpts.com
Thought I would just post to
Thought I would just post to this thread that there is a great video and web resource on table theming by EclipseGc here: http://drupal.org/node/290374 (Drupal 5 only at present)