1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

"For" loop within template

Discussion in 'XenForo Development Discussions' started by semprot, Aug 6, 2014.

  1. semprot

    semprot Active Member

    How to create "for" loop within template? I only see "foreach" loop example.

    I have an integer variable called $a which has a numeric value.
    I want to do something on template like
    <?php for ($i 1$i $a$i++) : ?>
    <b>Hello World</b>
    <?php endfor; ?>
  2. semprot

    semprot Active Member

    Anyone can help? :)
  3. AndyB

    AndyB Well-Known Member

    I suggest explaining in greater detail what it is you would like to do.
  4. semprot

    semprot Active Member

    For example i have this code on my template
    {xen:number $user.reputation_count}
    First example : if $user.reputation_count is 5, i want to print 5 asterisks.
    Second example : if $user.reputation_count is 10, i want to print 10 asterisks.

    Is there something like this?
    <xen:for "$user.reputation_count">
    span style="color:#F00">*</span>
  5. Chris D

    Chris D XenForo Developer Staff Member

    This would have the same effect:
    <xen:if is="{$user.reputation_count}">
        <span style="color: #F00">{xen:string repeat, '*', $user.reputation_count}</span>
    semprot likes this.
  6. AndyB

    AndyB Well-Known Member

    What are the limits for this reputation count? You wouldn't want to print 100 asterisks I assume. Is it more like a star rating system with 5 stars maximum?
  7. semprot

    semprot Active Member

    Thank you, i think this works :)

    At this moment it is 5 stars max :)

Share This Page