tutchi
March 28, 2016, 9:57am
1
Hello,
Is it possible to put after each line a “,” except on the latest one?
['<strong><?php echo $market->market()->html() ?></strong><br /><?php echo $market->place()->html() ?>']
<?php $i=0; foreach($page->markets()->toStructure() as $market): ?>
['<strong><?php echo $market->market()->html() ?></strong><br /><?php echo $market->place()->html() ?>']
<?php endforeach ?>
Ti_Gr
March 28, 2016, 10:36am
2
You can do this with css only:
strong:not(:last-child)::after {
content: ",";
}
but I think it would be better to wrap your data in a ul and each market in a li-element
This probably isn’t a “best practice”, but I find myself often “array_map” and “join”-ing stuff.
In your case you could do:
<?php
join(', <br>', array_map(function($market) {
return brick('strong', $market->$market->market()->html());
}, $page->markets()->toStructure());
?>