Post by xxvirusxx » Wed Nov 21, 2018 4:29 pm

Can anyone tell me if is wrong?
And if is wrong, how should be?

I don`t understand only 2 lines :)

Php

Code: Select all

<?php $flip .= '"'.$rthumb['flipimage'].'",' ?>
<?php $flipimages = rtrim($flip,','); ?>
Twig??

Code: Select all

{{ flip ~= '"'~rthumb.flipimage~'",' }}
{{ flipimages = flip|rtrim(',') }}
Tks

Opencart 3.0.2.0 with bugs fixed | Free extensions


Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm

Post by OSWorX » Wed Nov 21, 2018 6:02 pm

Why are you doing it that complicated?
Convert it in the controller:

Code: Select all

$flipimages = rtrim($flip,',')
And handover

Code: Select all

$data['flipimages'] = $flipimages;
or

Code: Select all

$data['flipimages'] =  rtrim($flip,',');
Then you need only

Code: Select all

{{ flipimages }}
Or do it inside the controller with implode.
Instead of

Code: Select all

$flip .= '"'.$rthumb['flipimage'].'",'
I never would 'work' inside the template (e.g. assigning vars) whenever possible!

Forum Rules [en]: viewtopic.php?f=176&t=200480
Forumregeln [de]: viewtopic.php?f=37&t=114208
Commercial Request: viewforum.php?f=88

Image


User avatar
Expert Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by pprmkr » Wed Nov 21, 2018 6:50 pm

PHP:

Code: Select all

$rthumb = array();

$rthumb[] = array(
	'id' => 1,
	'flipimage' => 'image1.jpg'
	);
$rthumb[] = array(
	'id' => 2,
	'flipimage' => 'image2.jpg'
	);
$rthumb[] = array(
	'id' => 3,
	'flipimage' => 'image3.jpg'
	);
$rthumb[] = array(
	'id' => 4,
	'flipimage' => 'image4.jpg'
	);

$flip = '';

foreach ($rthumb as $image) {
	$flip .= $image['flipimage'].',';
}

echo 'flip = ' . $flip . '<br />';

$flipimages = rtrim($flip,',');

echo 'trimmed flip = ' . $flipimages;

Twig:

Code: Select all

{% set rthumb = [
    {'id':'1','flipimage':'image1.jpg'}, 
    {'id':'2','flipimage':'image2.jpg'}, 
    {'id':'3','flipimage':'image3.jpg'}, 
    {'id':'4','flipimage':'image4.jpg'}
] %}

{% set flip = '' %}

{% for image in rthumb %}
	{% set flip = flip ~ image.flipimage ~ ',' %}
{% endfor %}

flip = {{ flip }}
<br />

{% set flipimages = flip|trim(',') %}

trimmed flipimages = {{ flipimages }}

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by OSWorX » Wed Nov 21, 2018 8:01 pm

And what is the reason behind to have such logic/operation inside the template?
Seeing such more and more instead of keeping templates clean.

Forum Rules [en]: viewtopic.php?f=176&t=200480
Forumregeln [de]: viewtopic.php?f=37&t=114208
Commercial Request: viewforum.php?f=88

Image


User avatar
Expert Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by xxvirusxx » Wed Nov 21, 2018 11:32 pm

Tks for tips @OSWorX

Is a nice and free ocmod extension for rollover images
https://www.opencart.com/index.php?rout ... n_id=32295

Trying to convert for free :)

Opencart 3.0.2.0 with bugs fixed | Free extensions


Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Who is online

Users browsing this forum: No registered users and 4 guests