Post by ioncart » Wed May 10, 2017 10:53 pm

I am editing the category.tpl to put a line break in the category name. I need to line break at the first space it encounters in $category['name']. Anyone know how to achieve this? thanks.

New member

Posts

Joined
Tue May 09, 2017 9:55 pm

Post by viethemes » Wed May 10, 2017 11:40 pm

You can try using this code

Code: Select all

preg_replace('/\s/', '<br />', $category['name'], 1)

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm


Post by ioncart » Wed May 10, 2017 11:48 pm

it does not work. I placed it in two spots in category.tpl as follows with no success.
<li><a href="<?php echo $category['href']; ?>"><?php echo preg_replace('/\s/', '<br />', $category['name'], 1); ?></a></li>

New member

Posts

Joined
Tue May 09, 2017 9:55 pm

Post by MrPhil » Thu May 11, 2017 1:04 am

Offhand I don't see anything obviously wrong with your PHP code. Just for giggles, you might try doubling the backslash ('/\\s/') and see if that has any effect. Maybe the single backslash was being eaten by the templating code, or something. There's a chance you might even have to double it again ('/\\\\s/').

Of course, you've checked that it's not something silly like forgetting to upload the edited file to the right place, or you edited the wrong file.

Active Member

Posts

Joined
Wed May 10, 2017 11:52 pm

Post by cyclops12 » Thu May 11, 2017 3:33 am

You may also need to goto extensions/modifications and click the refresh button to see changes

Active Member

Posts

Joined
Sun Sep 27, 2015 1:10 am

Post by artcore » Thu May 11, 2017 4:39 am

Or avoid escaping:

Code: Select all

echo implode('<br>', explode(' ', $category['name'], 2));
Last edited by artcore on Thu May 11, 2017 2:54 pm, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by viethemes » Thu May 11, 2017 9:53 am

You should follow cyclops12's recommendation, go to Admin > Extensions > Modifications > click on the Refresh button to rebuild modifications.

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm


Post by ioncart » Thu May 11, 2017 5:11 pm

the file i edited is category.tpl under view/theme/default/template/product/. i doubled the backslashes and then doubled them again as recommended. confirmed uploaded file was the modified one. clicked refresh under extensions modifications.
here is the code with the replacements although it still does not work. maybe i am editing the incorrect area. any more feedback would be welcomed.
<div class="row">
<div class="col-sm-3">
<ul>
<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo preg_replace('/\\s/', '<br />', $category['name'], 1); ?></a></li>
<?php } ?>
</ul>
</div>
</div>
<?php } else { ?>
<div class="row">
<?php foreach (array_chunk($categories, ceil(count($categories) / 4)) as $categories) { ?>
<div class="col-sm-3">
<ul>
<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo preg_replace('/\\s/', '<br />', $category['name'], 1); ?></a></li>
<?php } ?>
</ul>
</div>
<?php } ?>
</div>

New member

Posts

Joined
Tue May 09, 2017 9:55 pm

Post by ioncart » Thu May 11, 2017 5:23 pm

i removed this statement <?php echo $category['name']; ?> and put the word test in place to see if it would output test to no avail. I must be targeting the incorrect area. Hopefully somebody knows how to make this work.

New member

Posts

Joined
Tue May 09, 2017 9:55 pm

Post by ioncart » Thu May 11, 2017 5:36 pm

i did a bit more searching around only to find a header.tpl that more closely relates to the output of the categories in navbar. Replaced the <?php echo $category['name']; ?> with the text test to see test outputted on the category navbar as opposed to categories although it did not work.

New member

Posts

Joined
Tue May 09, 2017 9:55 pm

Post by viethemes » Thu May 11, 2017 10:59 pm

You should not quote with double slash. Could you provide your site URL and take a look about which are you want to change so we can take a look at it closer?

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm


Post by ioncart » Fri May 12, 2017 12:28 am

my screwup. if you patiently wait your file upload to finish, hit refresh in modifications all the change in the tpl display. the preg_replace('/\s/', '<br />', ,1) worked wonders. thanks again.

New member

Posts

Joined
Tue May 09, 2017 9:55 pm

Post by viethemes » Fri May 12, 2017 9:55 am

ioncart wrote:
Fri May 12, 2017 12:28 am
my screwup. if you patiently wait your file upload to finish, hit refresh in modifications all the change in the tpl display. the preg_replace('/\s/', '<br />', ,1) worked wonders. thanks again.
Glad to hear that the problem is solved :)

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm

Who is online

Users browsing this forum: No registered users and 13 guests