Page 1 of 1

LISE - Implode doesn't work?

Posted: Tue Feb 25, 2020 10:51 am
by brentnl
Hi,

I've made an instance with LISE, which contains several field definitions, and one of them is a checkbox group called 'distance', with the following options;

Code: Select all

2KM= <button class="btn btn-distance km2">2km</button>
4KM= <button class="btn btn-distance km4">4km</button>
8KM= <button class="btn btn-distance km8">8km</button>
Question one; if I edit the field definition, there is also a field called 'template' where at default the following line is being displayed;

Code: Select all

{$fielddef.name}: {$fielddef.value|implode:','}
, but changing it doesn't effect a thing. Also putting another value at the 'seperator' field doesn't seem to do anything?

Queston two, the main question; how do I manage to get rid of the comma's seperating the array? I'm calling the field in a Core::Page template with;

Code: Select all

{$item->distance|implode:''}
but nothing returns. If I remove the implode-part, it's getting displayed with the comma-seperation.

Re: LISE - Implode doesn't work?

Posted: Tue Feb 25, 2020 12:32 pm
by Jo Morg
brentnl wrote:Question one; if I edit the field definition, there is also a field called 'template' where at default the following line is being displayed;
\$1:
{$fielddef.name}: {$fielddef.value|implode:','}
, but changing it doesn't effect a thing. Also putting another value at the 'seperator' field doesn't seem to do anything?
It's not documented as it is still experimental, but to use the field definition template in a detail or summary template the you'll need to call the item using the View method:

Code: Select all

{$item->View()}
brentnl wrote:Queston two, the main question; how do I manage to get rid of the comma's seperating the array? I'm calling the field in a Core::Page template with;
\$1:
{$item->distance|implode:''}
but nothing returns. If I remove the implode-part, it's getting displayed with the comma-seperation.
The comma isn't separating an array: if has commas it is a string representation of an array. Implode in PHP joins the comma separated string in an array which, in a sense, is what you want, but is not displayable per se... You'll need to iterate through the array with a foreach.

Code: Select all

{foreach $item->distance|implode:'' as $one}{$one}{/foreach}
[/s]Note: this was not exact! Look at velden's post :)!
Thanks velden for the heads up ;) !

Re: LISE - Implode doesn't work?

Posted: Fri Feb 28, 2020 3:28 pm
by velden
I discussed briefly with Jo Morg and we agreed the last example should be with 'explode'. Further, I think that Smarty wants it in another order because of the parameter order in PHP. First the separator then the string value. So try:

Code: Select all

{foreach ','|explode:$item->distance as $one}{$one}{/foreach}

Re: LISE - Implode doesn't work?

Posted: Sun Mar 01, 2020 9:25 pm
by brentnl
velden wrote:I discussed briefly with Jo Morg and we agreed the last example should be with 'explode'. Further, I think that Smarty wants it in another order because of the parameter order in PHP. First the separator then the string value. So try:

Code: Select all

{foreach ','|explode:$item->distance as $one}{$one}{/foreach}
Thanks, this worked!

Another solution for my particular problem I found is;

Code: Select all

 {$item->distance|replace:',':' '}
This way the comma got replaced by nothing, which was exactly what I wanted.