0

I am confused on how to output links from a content type into a list in HTML. Currently I have the following code.

<div class="lenders-block-content clearfix">
  <ul>          
    <?php print render($content['field_link']) ?>
  </ul>     
</div>

The output just adds the links back-to-back within an <a> tag.

Is there a way to render the links so its outputted within a <li> tag?

I am using multiple links. When adding a content type you can add up to ten links.

4
  • I think you miss an <li> tag try with <ul> <li> <?php print render($content['field_link']) ?> </li></ul>
    – berramou
    Jun 21, 2019 at 10:38
  • @berramou - Hi Thanks for your reply, but issue is it will print all the links within the <li> instead of it printing several <li> tags. So I have multiple links, instead of just one link.
    – Moe
    Jun 21, 2019 at 10:41
  • Ok so it's multivalue field?
    – berramou
    Jun 21, 2019 at 10:45
  • @berramou yes, it is.
    – Moe
    Jun 21, 2019 at 11:38

1 Answer 1

0

As you mentioned in the comments you field is multivalue field so you should loop over it and render the item inside <li> tag something like the following:

<div class="lenders-block-content clearfix">
    <ul>
      <?php foreach ($content['field_link'] as $key => $link):?>
      <?php if (is_numeric($key)): ?>
        <li> <?php print render($link) ?></li>
      <?php endif;?>
      <?php endforeach;?>
    </ul>
  </div>
2
  • Thanks alot this has worked!.
    – Moe
    Jun 21, 2019 at 16:33
  • you are welcome, i'm glad that help!
    – berramou
    Jun 21, 2019 at 19:46

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.