Post by guntis.e » Sat Dec 21, 2019 7:06 pm

Ocmod itself works. But my regex search is reported as not found. Modification not created. What am I missing? Opencart 3.0.3.2.

Code: Select all

	<file path="catalog/view/theme/*/template/common/cart.twig">
		<operation error="log" info="">
			<search regex="true"><![CDATA[~{% for option in product\.option %}(.*)$~]]></search>
			<add position="replace"><![CDATA[{% for option in product.option %}{% if option.name != 'test' %}$1]]></add>
		</operation>
	</file>
Error log:
FILE: catalog/view/theme/default/template/common/cart.twig
NOT FOUND - OPERATIONS ABORTED!

And here is the code of line 11,12 of cart.twig:

Code: Select all

            {% for option in product.option %} <br />
            - <small>{{ option.name }} {{ option.value }}</small> {% endfor %}

Guntis
Image Partneris.lv - opencart web site development and support


Active Member

Posts

Joined
Fri Jan 28, 2011 4:20 am

Post by cyclops12 » Sat Dec 21, 2019 7:36 pm

You need to remove the backslash in your search DATA
<search regex="true"><![CDATA[~{% for option in product\.option %}(.*)$~]]></search>

Expert Member

Posts

Joined
Sun Sep 27, 2015 1:10 am

Post by guntis.e » Sat Dec 21, 2019 8:26 pm

backslash escapes the dot. I have tried also without it - still the same. It must be something else, as i tried also just text in regex, like ~for option in product.option~, it did not help

Attaching the ocmod file, that seems perfectly valid, but is not working.

What i need to achieve is insert some code between {% for option in product.option %} and <br />

Guntis
Image Partneris.lv - opencart web site development and support


Active Member

Posts

Joined
Fri Jan 28, 2011 4:20 am

Post by guntis.e » Sat Dec 21, 2019 11:00 pm

I found the cure!!!

$ as search for end of line seems not working. Instead [\n\r] can be used.

so the working code is

Code: Select all

	<file path="catalog/view/theme/default/template/common/cart.twig">
		<operation error="log" info="">
			<search regex="true"><![CDATA[~({% for option in product\.option %})(.*[\r\n])~]]></search>
			<add position="replace"><![CDATA[\1{# inline edit #}\2]]></add>
		</operation>
	</file>	
And hey - regex is the way how to get around the missing ibefore and iafter in ocmod :)

Guntis
Image Partneris.lv - opencart web site development and support


Active Member

Posts

Joined
Fri Jan 28, 2011 4:20 am

Post by straightlight » Sat Dec 21, 2019 11:17 pm

And hey - regex is the way how to get around the missing ibefore and iafter in ocmod
Glad to see it's working. However, since you're only editing one TWIG file, regex in this case is not required since the indexes do not need to be used with constant line tracking since \n\r is being tracked identically for each of these lines. The only problem with the suggestion above is whenever a \n\r is not involved in the line tracking and might still be considered an operation skipped.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by JNeuhoff » Sun Dec 22, 2019 10:40 pm

Instead [\n\r] can be used.
Isn't that dangerous? This assumes Microsoft style line ending, as used on Windows, whereas OpenCart is usually hosted on Linux servers which uses \n only for line endings.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by guntis.e » Mon Dec 23, 2019 2:10 am

Isn't that dangerous? This assumes Microsoft style line ending, as used on Windows, whereas OpenCart is usually hosted on Linux servers which uses \n only for line endings.
[\n\r] assumes \n or \r

If I really will need to find line ending, I will use (\r\n|\n|\r), which should include any possible line ending - windows or Linux. Because, even if the server is Linux, files from windows workstations could be created there with \r\n line endings.

The lesson learned for me by solving this ocmod problem is a) the regex line endings $ are not working, b) I can edit inline with regex any line, even multiline. :yahoo:

Guntis
Image Partneris.lv - opencart web site development and support


Active Member

Posts

Joined
Fri Jan 28, 2011 4:20 am

Post by straightlight » Mon Dec 23, 2019 2:12 am

The lesson learned for me by solving this ocmod problem is a) the regex line endings $ are not working, b) I can edit inline with regex any line, even multiline.
However, the lines without \r\n needed to be identically found without those criteria will be skipped, as explained above by using this method.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 420 guests