I have overridden my node tpl page and want to output variables from a field into html. The field is called: "Features Ticked"

I understand that this php code will output the information:

<?php print render($content['field_features_ticked']) ?>

I see the variables are all visible with css tags around them.

Is this the only way I can outpout this information as I want to strip the html tags, how do I do that?

I want to just output row by row then use html within the tpl file.

At the moment I get all these classes:

<div class="field field-name-field-features-ticked field-type-text field-label-above" style=".field-name-field-features-ticked: size">
<div class="field-label">Features/Ticked:&nbsp;</div>
<div class="field-items">
<div class="field-item even">Text 1</div>
<div class="field-item odd">Text 2</div>
<div class="field-item even">Text 3</div>

What I want to do it output just:

Text 1
Text 2
Text 3

Then wrap my own html around it.. I think I can override the field.tpl.php file to remove the classes, but I don't know how to output each line of text using php in 3 separate lines of code.

I thought i was something like:

<?php print render($content['field_features_ticked'][1]) ?>
<?php print render($content['field_features_ticked'][2]) ?>
<?php print render($content['field_features_ticked'][3]) ?>

But my knowledge of php kind of end there!


What you can do is to overwrite the field template.

To do that go and copy the field.tpl.php from core and rename it to field--features-ticked.tpl.php, and put it in your theme.

Then you can remove all the useless div's and classes.

EDIT : How to output the list items individually.

Let's say you have the array $content['field_features_ticked'], you can do like this.

  <?php foreach($content['field_features_ticked'] as $item) ?>
    <li><?php print $item; ?></li>
  <?php endforeach; ?>

This will create an unordered list, then loop through all the list items and print them out one by one.

NOTE: If you can't print out $item, you might do like this.

<?php print $item[LANGUAGE_NONE][0]['value']; ?>

Hope that is helps you out.

  • Ok, but how do I output each line of data one by one using PHP? – Rich Stevens Oct 9 '18 at 8:51
  • You might have an array of lists, you can loop through that using a foreach loop and print out the values like that. – user72672 Oct 9 '18 at 9:17
  • This is the question I am asking; how do you output this stuff as an array. I do not know, hence the question. – Rich Stevens Oct 9 '18 at 9:59
  • I have updated the answer – user72672 Oct 9 '18 at 10:06

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.