0

I am trying to search and replace some code I have got from VQCache. When I search in my code editor it finds it, but it throwing an error in the browser.

I think the "offset" amount is wrong. can anyone help?

<modification>

<id>Change Tabs</id>
<version>1.0</version>
<vqmver>2.4.1</vqmver>
<author>James B</author>

<file name="catalog/view/theme/*/template/product/product.tpl">
    <operation error="log">
        <search position="replace" offset="5"><![CDATA[
        <?php if ($pd_show_tab) { ?>
<a href="#tab-download"><?php echo $tab_download; ?></a>
<?php } ?>

<?php if ($youtube_code) { ?>
<a href="#tab-youtube"><?php echo $tab_youtube; ?></a>
<?php }?>
        ]]></search>
        <add><![CDATA[
        <?php if ($youtube_code) { ?>
<a href="#tab-youtube"><?php echo $tab_youtube; ?></a>
<?php }?>

        <?php if ($pd_show_tab) { ?>
<a href="#tab-download"><?php echo $tab_download; ?></a>
<?php } ?>
        ]]></add>
    </operation>

</file>

me9867
  • 1,519
  • 4
  • 25
  • 53

2 Answers2

0

If I understand correctly; VQMOD can only search a single line of code. What you have there is trying to search multiple lines of code which most likely throws an error.

'Multi-line Replace' Example

vQmod is limited to a single-line search, but you can use the "offset" attribute to blindly blanket additional lines of code in the replace.

Create a new text file and call it "multi-replace-demo.xml"

Add the minimum required xml structure

To replace multiple lines we use the "offset" attribute with replace. Count the number of total lines to replace and subtract one

as the main line is already covered by the replace command. In this example, there are 8 lines of code, so offset would be 7. When possible it's advised to avoid doing this .....

Read from source here: VQMOD Examples

  • Tried that along with different offset values, the search is failing in logs even though it finds that block in vqcache and vqmod when I find it. – me9867 Apr 01 '16 at 14:52
  • It looks like you are trying to search and change multiple lines of code at the same time with VQMOD. You might have an issue there. You may need to customized your product.tpl template to suit your needs. It would be less confusing. – Edward Koo Apr 01 '16 at 14:58
0

I just need to search for the one line I wanted that was at the top of the code block. Then it adds the lines on and works.

So here is the working code:

    <file name="catalog/view/theme/*/template/product/product.tpl">
    <operation error="log">
        <search position="replace" offset="5"><![CDATA[
        <a href="#tab-download"><?php echo $tab_download; ?></a>
        ]]></search>
        <add><![CDATA[
<a href="#tab-youtube"><?php echo $tab_youtube; ?></a>
<?php }?>

        <?php if ($pd_show_tab) { ?>
  <a href="#tab-download"><?php echo $tab_download; ?></a>
  <?php } ?>
        ]]></add>
    </operation>

  </file>

  </modification>
me9867
  • 1,519
  • 4
  • 25
  • 53