View previous topic :: View next topic |
Author |
Message |
Martine Smarty Rookie
Joined: 14 Jul 2018 Posts: 5
|
Posted: Sat Jul 14, 2018 6:50 am Post subject: Adding spaces between elements of a |
|
|
Hello,
I have this code where a list of extras if checked gets listed on a given page. I would like to have a comma and a space after each extra, if not last extra in the list
Code: |
{if !empty($item.extras)}
<div>
<span>{lang key='field_listings_extras'}:</span>
<span>{$item.extras}</span>
</div>
{/if}
|
Thank you in advance |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Jul 14, 2018 2:52 pm Post subject: |
|
|
An example of sourse data and the desired output could help better understand what you want. |
|
Back to top |
|
Martine Smarty Rookie
Joined: 14 Jul 2018 Posts: 5
|
Posted: Sat Jul 14, 2018 4:54 pm Post subject: |
|
|
I am very newbie to this I have a subrion cms and this is in a view listing tpl page.
What do you mean an example of souce code? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Jul 15, 2018 5:18 pm Post subject: |
|
|
Where did I say "source code" ? |
|
Back to top |
|
Martine Smarty Rookie
Joined: 14 Jul 2018 Posts: 5
|
Posted: Sun Jul 15, 2018 7:45 pm Post subject: |
|
|
Yes oops
The source data is php sql I don't know if that helps |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jul 16, 2018 4:35 pm Post subject: |
|
|
I don't need to know where it comes from, I need to see how it looks.
And what the intended result from that data. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Jul 21, 2018 10:01 am Post subject: |
|
|
Judging by his hints, he don't need foreach for that. |
|
Back to top |
|
Martine Smarty Rookie
Joined: 14 Jul 2018 Posts: 5
|
Posted: Tue Jul 24, 2018 7:28 pm Post subject: |
|
|
Hello,
found it
Code: | {if !empty($item.extras)}
<div>
<span>{lang key='field_listings_extras'} :</span>
<span>
{foreach $item.extras_formatted as $extra}
{lang key="field_listings_extras+$extra"}{if !$extra@last}, {/if}
{/foreach}
</span>
</div>
{/if} |
Thank you |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Jul 25, 2018 3:35 pm Post subject: |
|
|
Why not just Code: | {", "|join:$item.extras_formatted} | ? |
|
Back to top |
|
Martine Smarty Rookie
Joined: 14 Jul 2018 Posts: 5
|
Posted: Wed Jul 25, 2018 8:03 pm Post subject: |
|
|
Hello,
I tried, on another field, it did not work. The code I found working, does not put a comma at the end |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jul 27, 2018 1:57 am Post subject: |
|
|
I'm not sure, what you mean by that. |
|
Back to top |
|
|