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?

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

|improve this answer|||||
  • He wants to strip/remove tags, not add more... – No Sssweat Jul 28 '16 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. – Jimmy Ko Jul 28 '16 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. – No Sssweat Jul 28 '16 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. – Jimmy Ko Jul 28 '16 at 1:01
  • 1
    I get it now, all along he just wanted to add fields to the header section. – No Sssweat Jul 30 '16 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.

|improve this answer|||||

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.