I watched the latest Lullabot video on CCK and Views and I have a theming question as a result. I need to theme a views and print fields out on the views template page I am using. In the CCK Video they showed the format of code for printing out a cck field like such:
?php print check_plain($node-> title) ?> or <?php print $node-> field_job [0] [‘view’] ?>
Is this also how I could print out variables on my views template page?
Also, I was looking at an example of a templated views page recently and the variables looked a lot different. They looked like this:
<?php print $certification; ?> or <?php print $list_price; ?>
Where do you think the programmer generated the code from above?
Which style should I use?
Thanks,
Becky
Comments
I think reading this might help
http://drupal.org/node/352970
This was pretty helpful in
This was pretty helpful in terms of giving me more knowledge but I tried their technique and it didn't work.
I put this in my template file views-view--technical-documents.tpl.php, the name of my high level view but i just get a blank page.
And yes, I have the devel module installed and enabled.
please help! why would i go white?
Becky
try this, or could be memory
Could be php out of memory, that's typically the cause of the white screen.
Try this to rule of devel module:
I checked my php memory and
I checked my php memory and it wasn't giving me an error on the status page.
Used the snippet you have up there and it made my page go blank. It loaded but there was nothing on the page other than the views title.
Becky
me too
I can't get dsm() to work.
At the level you are working, you cannot, I do not think, get to individual fields. You need to overide a lower level template like the row style template. What are your Style and Row Style settings?
I have another template for
I have another template for my fields view but the instructions on that article you said, said to use a higher template than a field template. Also, to clarify when I put this on my page i get a white screen:
as well. But If I put this on my page:
I don't get a white screen but I don't get anything helpful. Seems like the closing ?> is doing something.
Anyway, my row settings: Field which title inline. Not sure it that makes a difference.
style settings : unformatted, grouped by taxonomy term.
Becky
not sure about article yet
the overall view template does not appear to provide a $fields variable for me when I choose row style = fields. The $rows variable is there, but it is the complete, formatted output.
I know what that article says, but I don't think it is clear. If you want control of each field, you are going to work inside your fields template, not the overall view template.
Ok I grabbed <?phpprint
Ok I grabbed
off your last post there and now it works. It printed out the $field in a plain text way.
hmm....
Here is what I get in my overall view template for defined variables, when I have a row style of fields, I don't see a 'fields' variable at all.
I think you are right. I
I think you are right. I added the code you showed me to my fields template and it printed the variables out.
I got this:
which are the names of my fields.
Now one more question, how do I put these fields on my actual template. Can you give me an example?
from listening to the CCK video on printing out variables, I thought i would have a number and word or something to print out, like this
<?php print $node-> field_job [0] [‘view’] ?>and it made sense at the time becuase they were using the dsm code and looking at it through Krumo but I'm not sure what to do with this particular page......Thanks for all your help on this, btw. I really appreciate it.
Becky
this should help
this is from the core fields template in views, in the video was it a node style view?
I think it was probably a
I think it was probably a node style view they were using but in the styling views section, they didn't get very deep; they just talked about how you could generate theme files using views 2 now.
http://beta.wimaxforum.org/technical_release1 this is actually a link to my views if you want to see it so far. I'm trying to mix js and views to get a result like this : http://www.wimaxforum.org/training/courses. Someone else did that page and I'm trying to replicate it.
It's proving rather hard.
Becky
another option I like better
Based on your web site sample:
If you set up a view that is row style 'node', then what you get in your view is a complete list of nodes, with all the data for each node. Then, you can create your own node template for your content type. So, lets say you create a content type called 'news'. You can create a template called node-news.tpl.php. This will then handle the output for your 'news' nodes. And, in this template, you can actually have a section of code to handle output for a list of nodes, and a section of code to handle viewing one single node. I would recommend locating your node.tpl.php file for the theme you are using then just making a copy, naming it according to your content type.
Inside this node template, there is a variable called $page. If this value is 0, it means you are NOT viewing a single page for a node, you are on a list type page, so you can do this
This is really interesting.
This is really interesting. If I did it the way you suggest above, could I still use the js effect that is illustrated on the page: http://www.wimaxforum.org/training/courses ? That is proving to be difficult too btw. I was trying to go off of what the other person did in their js but it's not working yet.
For example
This part: is supposed to show a download link, so people can download the file, but it's not working
dl_upload_fid is the variable for my upload widget that i made in CCK but this isn't showing up on the page.
Anyway, I'm going to give it a shot your way. Thanks for the advice!
Becky
well, they have a jquery affect applied
When their page loads jquery locates all their specific links and applies some custom show / hide functionality. I don't know exactly how they did their pages, probably something with either a custom module or a custom node template. So, the short answer is, yes you can do it, the long answer is, it might not be simple unless you know some javascript / jquery or have a js person handy.
He didn't use a module, it
He didn't use a module, it was custom code. For example in the css there is this:
and in the js there is this:
In the view there is this:
Either way, cannibalizing this code is not working.....
Becky
I don't think this is going
I don't think this is going to work. I am going to try it but, one reason is that I needed everything to group by taxonomy term, under style: unformatted and I don't seem to be able to do this when I'm doing row style as node.... unless you know of an alternative way to achieve this?
Becky
you can still get to the fields in unformatted / field view
You can still get to individual fields by making it Field rather than Node. If you look at the core view for the unformatted row style, you will see that the data is in $fields, and the raw data is in an array called $rows.
Concering the javascript, I see his javascript and CSS, but somewhere there must be a line of code (unless maybe drupal just does this for you) to add his custom "click handler" code to all those link tags.
Anyway, so change to unformatted row style and it will let you choose your grouping field. Then use your original template override for row style to output your individual fields. You can basically use $fields like this:
this is formatted content, meaning if any of your fields contain html, Drupal will have processed it based on your selected input format, made sure it is safe, etc. If you need unformatted data, it is there somewhere, I'd have to hunt to find it.
I'm going to look again, because I think there is a way to do a "group by" with a node view, too.
this might help
Have not tried it yet:
http://drupal.org/project/views_groupby
http://drupal.org/node/389230
Thanks, I'll try these out
Thanks, I'll try these out today.
??
??
Views Template Print Individual Fields Example
Goal:
Print individual fields in an Views template file (e.g. views-view-fields--today.tpl.php) at the Row Style level to give greater control over theme'ing. The purpose of this is to wrap each individual field in your own custom classes using a single template file for all of your rows.
First... Get your field IDs
This is just a quick and easy way to see what your fields are (they are different between, node, cck, taxonomy, etc. I tend to forget the syntax/which vocabulary ids so I do it this way).
In your browser this will generate output similar to this: title field_flyer_fid field_date_value tid_3 tid_4 tid tid_2 tid_1 tid_5 . These are the IDs in your view and what you are going to be comparing against.
Secondly... Write if statements to evaluate which field is being printed.
This is a pretty straight-forward string comparison. It's a bit of extra code, but sense you can't just print $fields['field_name']->content in the row style output template... this is my work-around.
To take it one step further
The only reasons I've even done this in the first place (instead of just styling the views classes as is) are: One, I want all my classes to be consistent across the website (views and non-views). More importantly, I wanted to wrap fields in groups to make left and right columns. Something to this effect... .views-left-column: field 1, field 2, field 3 ... .views-right-column: field 4, field 5, field 6.
This involved a bit of creative thinking... Here is an example of how this works:
What I've done is open the column when it detects the correct field name and than close the column when it detects the correct field name; telling it to open and close at the appropriate fields. I than clear to make sure the columns are equal heights (CSS, not Drupal).
Finally...
Note that you'll automatically get the zebra odd/even effect from the Views display output template file. The above code will be wrapped .views-rows-odd, than .views-row-even...
The only last important thing to note about using this method is that... It doesn't matter in what order you put your fields in the template! Huh? Remember how we printed the IDs? title field_flyer_fid field_date_value tid_3 tid_4 tid tid_2 tid_1 tid_5. This is the order that your fields are going to be printed in, no matter what order you put your if statements... All we are doing is seeing what field and printing it. To adjust the order, do this directly in your Views UI.
Thank you for the write up.
Thank you for the write up. This was very interesting and helpful!
Becky
Thanks for that great write
Thanks for that great write up.(not that I completely understand it) it helped be solve my views theming problem.
If you template out cck
If you template out cck fields, can you do if statements then, too?