Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match Twig include tags with extra parameters #90

Merged
merged 2 commits into from
Mar 22, 2023
Merged

match Twig include tags with extra parameters #90

merged 2 commits into from
Mar 22, 2023

Conversation

braver
Copy link
Contributor

@braver braver commented Jun 14, 2022

Ensures matches for just the file for tag style with extra parameters:

{% include 'template.html' with {'foo': 'bar'} %}

https://twig.symfony.com/doc/3.x/tags/include.html

Previously the regex would match from the first quote all the way to the last quote, but it shouldn't include the extra object with parameters.

Tested in regex101

ensures matches for just the file for tag style with extra parameters:
```
{% include 'template.html' with {'foo': 'bar'} %}
```

https://twig.symfony.com/doc/3.x/tags/include.html
@jfcherng
Copy link
Contributor

jfcherng commented Jun 14, 2022

This PR is fine for sure.


I am using https://github.com/jfcherng-sublime/ST-my-settings/blob/dc509e19387cfa9ad827e78ee3b4dbb7e2f83791/Packages/User/HyperClick.sublime-settings#L80-L86 (although ' can be used in filename actually)

I think we don't have to match the rest of the string right after we have found the filename (the leading {% is quite a strong assertion). Anyway, merging them gives better performance and maintainability(?).

@braver
Copy link
Contributor Author

braver commented Jul 1, 2022

Hm, yours has less repetition for sure, but for some of my test cases it doesn't work. You seem to have dropped the {{ include('file', {params}) }} form.

<div id="regular-event">
    <section class="eticket">
        {{ include('Etickets/_eticket_header.html.twig', {
            event : event,
            production : production,
            type: 'regular'
        }) }}
        <div class="eticket-body">
            {% for ticket in tickets %}
                {{ include('Etickets/_eticket_body.html.twig', { ticket: ticket, type: 'regular'}) }}
            {% endfor %}
        </div>
    </section>
</div>

But yeah, you don't have to match all the way to the end of the statement. The opening of the statement and the initial include, etc., keyword are good indicators of the intent.


Edit: added example.

@braver
Copy link
Contributor Author

braver commented Mar 22, 2023

@aziz are you still maintaining this package? I would like to help out.

@cristianl cristianl merged commit 0e60fa3 into aziz:master Mar 22, 2023
@cristianl
Copy link
Collaborator

I cannot add collaborators but I'd vouch for @braver and @jfcherng

@braver
Copy link
Contributor Author

braver commented Mar 22, 2023

@cristianl thanks for merging! Can you tag a release with the latest changes?

@aziz to consider: we could also move the repo to the SublimeText org where multiple experienced package developers maintain lots of packages.

@braver braver deleted the fix-twig-with branch March 22, 2023 17:27
@cristianl
Copy link
Collaborator

2.6.0 is now up. Sorry for the long delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants