By n00b0101 on
I'm desperately trying to put two fields within a parent div. I've tried doing this in views-view-field--myfield.tpl.php, and it is so totally not working.
Right now, the output looks like this:
<div class="views-field-field-content-image-embed">
<span class="field-content"><div class="listing-row-image"><a href="/node/10"><img src="/files/images/sampimg.png" alt="" title="" class="custom_url" width="50"></a></div>
<div class="views-field-title">
<span class="field-content"><a href="/node/10" title="My Fancy Title" alt="My Fancy Title">My Fancy Title</a></span>
</div>
<div class="views-field-body">
<div class="field-content"><p>blah blah blah...</p></div>
</div>
But, I want it to look like this:
<div class="views-field-field-content-image-embed">
<span class="field-content"><div class="listing-row-image"><a href="/node/10"><img src="/files/images/sampimg.png" alt="" title="" class="custom_url" width="50"></a></div>
<DIV CLASS="MYROW">
<div class="views-field-title">
<span class="field-content"><a href="/node/10" title="My Fancy Title" alt="My Fancy Title">My Fancy Title</a></span>
</div>
<div class="views-field-body">
<div class="field-content"><p>blah blah blah...</p></div>
</div>
</DIV>
I tried adding the
in views-view-field--title.tpl.php and then the closing
in views-view-field--body.tpl.php, but it seems to just insert the closing div for me in the first tpl file.
Is there a way to preprocess these fields or something? I've been messing around based on some examples I've seen around the site, but I'm just not getting it. It's seriously going to make me cry like a wee little girl...
Comments
node templates
Hi noob,
I'm having some difficulty with views-view-fields.tpl.php and views-view-field.tpl.php, myself. Not sure I know exactly what you're trying to do, but I sympathize with the craziness of getting into the tpl files.
One thing you can do to get the illusion of "fields" without actually using the "fields" option in Views is to
1. In your view, select row style as 'Node'.
2. In your theme folder, duplicate node.tpl.php and rename it to node-views-MYVIEW.tpl.php
--> this will format each node pulled by the view using your new node-views-MYVIEW.tpl.php. You can then select which fields to directly write to the page rather than relying on the views interface to do so
3. In node-views-MYVIEW.tpl.php set up the HTML as you'd like it to appear, using the placeholders for the data where they need to go. So you have to call your field variables directly and then place them within your own HTML markup (I'm assuming you are using CCK). If I have a field named "caption", I'd use the following code to get my caption data into the template:
So an example of what your node-views-MYVIEW.tpl.php might look like, could be:
Really not sure if this solves your problem. I find the CONTEMPLATE module useful for dev (I don't use it for output) just because it cracks the $content variable for any content type and lets you see what variable calls you need to make in order to get your field data directly into your template files.
Thank you for the great
Thank you for the great explanation!
I noticed that I can print the same info using below two choices:
print $node->field_firstname[0]['view'];print $node->content['field_firstname']['field']['items'][0]['#item']['value'];I was wondering which is better to use? Or what the difference is?
Thank you
Over my head
You're welcome! Glad it helped. I'm not sure about the answer to this though. My "feeling" is that the first is a more direct query to the info. The second drills into the $content variable. So if you somehow restrict what information is processed to the $content variable, you're not going to get the information (I think you can do that under Display Settings for the content types when you choose "exclude"). The first will always be there, as it is a part of the node object.
But I'm guessing about this. Personally, I just like the shorter versions better. ;)
awesome - i like the shorter
awesome - i like the shorter version as well =)
thanks again for your great explanation!
I think...
I'm no expert on this, just learning myself in fact, but the difference between the two ways of accessing the same information is that the top one is using Drupal functions to access data in a shorthand way, the second way is the manual way of drilling down into the data array of the node object (Not sure if this is the correct terminology though, so don't quote me on it.)