1

I cannot for the life of me figure out how to print the value of a field in the 'fields' template. Currently, I'm doing this to strip the unnecessary html (don't laugh):

<?php $shortContent = $fields['field_short_name']->content; ?> <?php $shortText = strip_tags($shortContent); ?> <?php $strategy = $fields['title']->content; ?> <?php $cleanStrategy = strip_tags($strategy); ?> <?php $company = $fields['field_money_manager_company']->content; ?> <?php $cleanCompany = strip_tags($company); ?> <?php echo '<img class="logo" src="/sites/all/themes/trust/img/mmx-logos/' . $shortText . '-logo.png" />'; ?> <div class="row-heading"> <?php echo '<h2>' . $cleanCompany. '</h2>'; ?> <?php echo '<h3>' . $cleanStrategy . '</h3>'; ?> </div><!--end row-heading--> 

How can I just get the value of the fields without having to print the entire 'content' and then strip the unnecessary elements?

1
  • The views UI provides configuration to strip out all the extra structural markup (see drupal.stackexchange.com/questions/156358/…). You might be able to do that and forgo the templating altogether. Commented Jul 28, 2016 at 0:51

2 Answers 2

2

I guess you want to create a row header which contains some value from other fields. If it is your case, I will suggest you this solution.


Use fields in format

Format of views

Add field Global: custom text

Global: custom text

Then you can use the token, which is the value of field, with your custom HTML structure.

Settings of custom text

Please note that custom text field must be placed after the field you want to use. In my case, it is title. You need to exclude it from display, otherwise, there will be 2 titles.

enter image description here

7
  • He wants to strip/remove tags, not add more... Commented Jul 28, 2016 at 0:51
  • @NoSssweat He asked ** how to print the value of a field in the 'fields' template**. I just guess what he want is to customize the HTML structure of some of the field value. Commented Jul 28, 2016 at 0:55
  • Title says: "Print just the value of Views field inside of views-view-fields template" by "just the value" he means he doesn't want <div>value</div> he just wants value. Hence he is using the strip_tags() function, but he wants to know if there is a better/alternative way to achieve this. Commented Jul 28, 2016 at 0:58
  • 1
    @NoSssweat <div class="row-heading"> make me think that he want a header for each row. So it makes sense to create a field to group some other field values. By using the token in custom text, it won't have <div> wrapper. Commented Jul 28, 2016 at 1:01
  • 1
    I get it now, all along he just wanted to add fields to the header section. Commented Jul 30, 2016 at 1:24
1

How can I just get the value of the fields without having to print the entire 'content' and then strip the unnecessary elements?

You can by using raw instead of content

<?php $fields['field_name']->raw; ?> 

Alternatively, you could keep using content, but strip all the unecessary markup that views provides. My answer here shows you how to.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.