Question

I am wanting to remove the icons from the h1 title element in opencart admin panel. I'm trying to use an asterisk as a wildcard for the file name, but it's not working out. The docs says the search data:

<h1><img src="view/image/*.png" alt="" /> <?php echo $heading_title; ?></h1>

should be a valid regex pattern, though I'm not familiar with regex. How can I do this correctly in vqmod?

<file name="admin/view/template/*/*.tpl">
    <operation>
        <search regex="true" position="replace"><![CDATA[
            <h1><img src="view/image/*.png" alt="" /> <?php echo $heading_title; ?></h1>
        ]]></search>
        <add><![CDATA[      
            <h1><?php echo $heading_title; ?></h1>
        ]]></add>
    </operation>
</file>
Was it helpful?

Solution

In vQmod, the regex still needs to have its delimiters. You are also better off just using a generic search for the <h1> since you are setting it to just the heading title.

<file name="admin/view/template/*/*.tpl">
    <operation>
        <search regex="true" position="replace"><![CDATA[~<h1>.*?</h1>~]]></search>
        <add><![CDATA[<h1><?php echo $heading_title; ?></h1>]]></add>
    </operation>
</file>

OTHER TIPS

In regex, an asterisk * is a quantifier which means match zero or more times.
I think you want to match anything, one or more times. You do that with .+. Ofcourse you want it ungreedy, so the final pattern is .+?.

  • . : match anything
  • + : a quantifier which means match one or more times
  • ? : + followed by ? means to match ungreedy

Let's apply the above in the code:

<h1><img src="view/image/.+?\.png" alt="" /> <?php echo preg_quote($heading_title); ?></h1>
  • We need to escape the dot in \.png
  • We'll use preg_quote() to escape properly regex reserved characters in the $heading_title variable
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top