LISE - Implode doesn't work?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
brentnl
Power Poster
Power Poster
Posts: 493
Joined: Mon May 11, 2009 4:35 pm

LISE - Implode doesn't work?

Post 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.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1968
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE - Implode doesn't work?

Post 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 ;) !
Last edited by Jo Morg on Sat Feb 29, 2020 8:59 pm, edited 1 time in total.
Reason: Added a correction note
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE - Implode doesn't work?

Post 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}
brentnl
Power Poster
Power Poster
Posts: 493
Joined: Mon May 11, 2009 4:35 pm

Re: LISE - Implode doesn't work?

Post 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.
Post Reply

Return to “Modules/Add-Ons”