XF 2.0 Trailing comma in foreach loop, syntax template

LPH

Well-known member
The foreach loop needs to be comma separated. Currently, a trailing comma exists for the last category. How can this be removed?

In PHP, it might be as simple as rtrim($my_string,','); but what is used in the templates?

Code:
            <div class="contentRow-minor contentRow-minor--hideLinks">
                <ul class="listInline listInline--bullet">
                    <li>{{ phrase('by_user_x', {'name': $latestpost.postAuthor}) }}</li>
                    <li><xf:date time="{$latestpost.postDate}" /></li>
                    <li>
                        <xf:foreach loop="$latestpost.postCategoryNames" value="$Categoryname">
                            {$Categoryname},
                        </xf:foreach>
                    </li>
                </ul>
            </div>
 
Last edited:
Use...
Code:
<ul class="listInline listInline--comma">
And don't put the comma after {$Categoryname}
 
  • Like
Reactions: LPH
More precisely..

Code:
            <div class="contentRow-minor contentRow-minor--hideLinks">
                <ul class="listInline listInline--bullet">
                    <li>{{ phrase('by_user_x', {'name': $latestpost.postAuthor}) }}</li>
                    <li><xf:date time="{$latestpost.postDate}" /></li>
                    <li>
                        <ul class="listInline listInline--comma">
                            <xf:foreach loop="$latestpost.postCategoryNames" value="$Categoryname">
                                {$Categoryname}
                            </xf:foreach>
                        </ul>
                    </li>
                </ul>
            </div>

OR
Code:
            <div class="contentRow-minor contentRow-minor--hideLinks">
                <ul class="listInline listInline--comma">
                    <li>{{ phrase('by_user_x', {'name': $latestpost.postAuthor}) }}</li>
                    <li><xf:date time="{$latestpost.postDate}" /></li>
                    <li>
                         <xf:foreach loop="$latestpost.postCategoryNames" value="$Categoryname">
                             {$Categoryname}
                         </xf:foreach>
                    </li>
                </ul>
            </div>
OR
Code:
            <div class="contentRow-minor contentRow-minor--hideLinks">
                <ul class="listInline listInline--bullet">
                    <li>{{ phrase('by_user_x', {'name': $latestpost.postAuthor}) }}</li>
                    <li><xf:date time="{$latestpost.postDate}" /></li>
                </ul>
                <ul class="listInline listInline--comma">
                     <xf:foreach loop="$latestpost.postCategoryNames" value="$Categoryname">
                         {$Categoryname}
                     </xf:foreach>
                </ul>
            </div>


And be sure your template has the core_list.less css loaded.

You need to work out what you want from there. ;)
 
Last edited:
And be sure your template has the core_list.less css loaded.

I’d tried all the above so I wonder if it is my not loading the core_list.css in the template. I’ll try when I’m on a computer.

Thank you.
 
It should be if the page loads the core.less template. It's automatically loaded in the core css.
 
To make this work you need <li>s as well, they won't be generated automatically. So the code has to be:

Code:
<ul class="listInline listInline--comma">
    <xf:foreach loop="$latestpost.postCategoryNames" value="$Categoryname">
        <li>{$Categoryname}</li>
    </xf:foreach>
</ul>
 
To make this work you need <li>s as well, they won't be generated automatically. So the code has to be:

Code:
<ul class="listInline listInline--comma">
    <xf:foreach loop="$latestpost.postCategoryNames" value="$Categoryname">
        <li>{$Categoryname}</li>
    </xf:foreach>
</ul>
Yep, my mistake. Thanks!
 
Top Bottom