1

I have a view that has two fields, A and B. Both of these fields are modified using a views-view-field--myfield.tpl.php file.

In my output, I want the fields to be displayed as:

AB (no space in between the values)

However, no matter what I do, it seems that Views puts a space between the two fields. I am using an Unformatted list and under Settings I have unchecked Add views row classes as well as Add striping (odd/even) rows classes. This has no effect on the spacing.

Under Settings for Fields, I have unchecked Provide default field wrapper elements. Again, the spacing remains.

I tried rewriting the results of the fields by inputting [field_fieldA][field_fieldB] under Rewrite the output of this field, but, while this output is shown in the preview in the Views admin interface, it is overwritten by the views-view-field--myfield.tpl.php file for the relevant field.

How can I output two values, both of which are output via template files, without a space between them?

  • Have you tried "Remove whitespace" under Rewrite Results? If checked, all whitespaces at the beginning and the end of the output will be removed. – Volker Apr 28 '13 at 6:44
  • @Volker I just tried that but it has no effect. I think the whitespace I am trying to remove is somehow produced by Views itself. – Patrick Kenny Apr 28 '13 at 6:53
  • Any chance the field is already tied to a css rule? some <p> margin, etc... – Volker Apr 28 '13 at 7:14
  • @Volker This is a site I just made a couple hours ago still using the Bartik theme. – Patrick Kenny Apr 28 '13 at 7:15
  • You can definitely do it with rewrite results, but I'm not sure what the problem is you are having with templates when you do that. – rooby Apr 28 '13 at 7:25
2

I just created a quick View here that had three fields:

1.  Node title.
2.  Node type.
3.  Global Custom Text Area

I changed the HTML Element and Wrapper HTML Elements to SPANs for the first two fields and also set them both to be excluded from display.

For the Global Custom Text Area, I rewrote its output to be [title][type] and got the titles smashed right up next to the node types without a space.

ADDITION:

You could also copy views-view-field.tpl.php to views-view-fields--smashed.tpl.php (or whatever your Views name is :) and then remove all the whitespace from there, eg, this template looks nice like this:

 <?php something ?>
   <?php something else ?>
   <?php something else again ?>
 <?php yadda yadda ?>

and each of those lines and indents puts in the whitespace that is causing your grief.

If instead this is saved as

 <?php something ?><?php something else ?><?php yadda yadda ?><?php one really big long line of code without any intervening tabs or new lines or spaces ?>

and your view will be created with the <divs> or <spans> smashed right up next to each other in the row. Then CSS it up the way you want.

  • Thanks, this works if you can use the default output of the view. However, in this case, I am using template files. If I use [title] etc. in a global custom text area, I will get the default views output, not the template file output that I need. – Patrick Kenny Apr 28 '13 at 14:40
  • Grrr. Hmm. Not sure what you are doing in your individual field templates, but (almost) every Views template has access to the entire View Object as the $view variable, so, you could make a template for a field that crafts what you want from any other field by accessing whatever you need via $view->result. – Jimajamma Apr 28 '13 at 14:48
  • Using the View Object allowed me to find a solution by simply lining up three print statements together. Many thanks! – Patrick Kenny Apr 28 '13 at 15:12

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.