Page 1 of 1

VQMOD find multiple lines

Posted: Sun Oct 13, 2019 4:19 pm
by psytanium
Hello,

Im not sure if I can find and add after multiple lines using VQMOD, I need some explanation :-\

Can someone tell me why this isn't working :

Code: Select all

<operation error="skip">
            <search position="after"><![CDATA[<td class="text-right"><a href="{{ user.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
                </tr>]]></search>
            <add><![CDATA[{% endif %}]]></add>
        </operation>
The file is admin/view/template/user/user_list. twig

Re: VQMOD find multiple lines

Posted: Sun Oct 13, 2019 5:35 pm
by cyclops12
There is no admin/view/template/user/user.twig

Re: VQMOD find multiple lines

Posted: Sun Oct 13, 2019 6:02 pm
by psytanium
cyclops12 wrote:
Sun Oct 13, 2019 5:35 pm
There is no admin/view/template/user/user.twig
User_list.twig

Re: VQMOD find multiple lines

Posted: Sun Oct 13, 2019 6:42 pm
by cyclops12
You cant search for multiple lines using vqmod/ocmod
You would have to search one line then use offset to go either side of searched line.
This may help you work out how to use vqmod

What are you trying to achieve ?

Re: VQMOD find multiple lines

Posted: Sun Oct 13, 2019 8:28 pm
by psytanium
cyclops12 wrote:
Sun Oct 13, 2019 6:42 pm
You cant search for multiple lines using vqmod/ocmod
You would have to search one line then use offset to go either side of searched line.
This may help you work out how to use vqmod

What are you trying to achieve ?
I'm trying to change this code in user_list.twig

Code: Select all

{% for user in users %}
<tr>
        <td class="text-center">
        {% if user.user_id in selected %}
                <input type="checkbox" name="selected[]" value="{{ user.user_id }}" checked="checked" />
        {% else %}
                <input type="checkbox" name="selected[]" value="{{ user.user_id }}" />
        {% endif %}
        </td>
        <td class="text-left">{{ user.username }}</td>
        <td class="text-left">{{ user.status }}</td>
        <td class="text-left">{{ user.date_added }}</td>
        <td class="text-right"><a href="{{ user.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
</tr>
{% endfor %}
to this

Code: Select all

{% for user in users %}

{% if user.username == "anyone" %}  <-- I want to add this

<tr>
        <td class="text-center">
        {% if user.user_id in selected %}
                <input type="checkbox" name="selected[]" value="{{ user.user_id }}" checked="checked" />
        {% else %}
                <input type="checkbox" name="selected[]" value="{{ user.user_id }}" />
        {% endif %}
        </td>
        <td class="text-left">{{ user.username }}</td>
        <td class="text-left">{{ user.status }}</td>
        <td class="text-left">{{ user.date_added }}</td>
        <td class="text-right"><a href="{{ user.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
</tr>
                
 {% endif %}  <-- I want to add this
                
{% endfor %}
If VQMOD cannot search 2 lines, this mean I cannot find and add after this

Code: Select all

<td class="text-right"><a href="{{ user.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
</tr>
But I can find and replace this

Code: Select all

<td class="text-right"><a href="{{ user.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td></tr>
Thank you for the support

Re: VQMOD find multiple lines

Posted: Sun Oct 13, 2019 8:50 pm
by psytanium
I used index=2 in the search command, it worked, I searched for the second {% endif %}, but what if another extension or I added a 3rd {% endif %} in between. You think I should another find way of find and add ?

Re: VQMOD find multiple lines

Posted: Sun Oct 13, 2019 10:20 pm
by cyclops12
Entirely up to you but i would probably search for code that isnt repeated if possible
something like

Code: Select all

<operation error="log">
            <search position="after"><![CDATA[{% for user in users %}]]></search>
            <add><![CDATA[{% if user.username == "YOUR_ADMIN_NAME" %}]]></add>
        </operation>
        <operation error="log">
            <search position="after" offset="1"><![CDATA[<td class="text-right"><a href="{{ user.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
                ]]></search>
            <add><![CDATA[{% endif %}]]></add>
        </operation>