0

I have a template views-view-fields--services.tpl.php

I don't want to iterate over the array of fields as I know which each of them are in this case.

I want to simply:

<div>
  <?php echo $row->title; ?>
</div>
<div>
  <?php echo $row->image; ?>
</div>

Doesn't appear to be a higher level template which might have this context of data???

UPDATED CODE SAMPLE:

views-view--services.tpl.php:

<!-- Services -->
<section class="site-section section-details">
  <?php print $rows; ?>
</section>

views-view-unformatted--services.tpl.php:

<?php foreach ($rows as $id => $row): ?>
  <alex>
    <?php print $row; ?>
  </alex>
<?php endforeach; ?>

views-view-fields--services.tpl.php:

<?php foreach ($fields as $id => $field): ?>

  <?php /*print $field->class;*/ ?>
  <?php print $field->content; ?>

<?php endforeach; ?>

Results in:

<section class="site-section section-details">
    <alex>

    <span>Entry #1</span>  

    <div><img src="http://temp.local/sites/foo/test.png" width="280" height="280" alt=""></div>  

    <div><p>Briefly describe which problems we can help with.</p>
</div>  
  </alex>
  <alex>

    <span>Entry #2</span>  

    <div><img src="http://temp.local/sites/foo/test2.png" width="280" height="280" alt=""></div>  

    <div><p>Quickly describe the services we offer or how our services can help?</p>
</div>  
  </alex>
</section>
2
  • Where is the markup between the <alex> tags coming from??? I want just the raw field data in a per-row context so I can simply write my required markup and echo each field (custom fields but I know what they are Commented Jan 29, 2014 at 21:30
  • In your view you probably need to strip the html tags as they are rendered by default in the view. Commented Jan 29, 2014 at 22:29

1 Answer 1

0

Have a look at views-view-field.tpl.php. It' not used by default views, but available as a template override.

Edit: In views-view-fields.tpl.php you can also use $fields['my_field_name']->content; to access individual fields, but this will give you the fields default markup as well. The raw values can be accessed with $fields['my_field_name']->raw but those values must be proper sanitized before printing.

5
  • I've tried that but VIEWS are still producing markup?!?! I've update my post with templates and code Commented Jan 29, 2014 at 21:25
  • @Alex Did you see the slight difference? I'm not relating to views-view-fields.tpl.php
    – berliner
    Commented Jan 29, 2014 at 21:44
  • I think I did but both fields and field are called once for each field...I want to use a template one step higher and basically output all 4 or five fields at once in the grid markup I have in place, if that makes any sense? Commented Jan 29, 2014 at 21:51
  • @Alex I have updated the answer, does this help now?
    – berliner
    Commented Jan 29, 2014 at 21:59
  • Yes it might...I dumped the $row variable in the context of views-view-field.tpl.php and this has all the info but if I can use $fields['name']->content thats even better :) Commented Jan 29, 2014 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.