Skip to content

lint:twig throws warning, doesn't display anything helpful #52778

@tacman

Description

@tacman

Symfony version(s) affected

6.4-RC2

Description

bin/console lint:twig templates/owner -vvv

In TwigPreLexer.php line 266:
                                             
  [ErrorException]                           
  Warning: Uninitialized string offset 9243  
Example

How to reproduce

symfony new bug --webapp --version=next && cd bug
composer require twig/markdown-extra twig/inky-extra twig/cssinliner-extra symfony/stimulus-bundle symfony/ux-twig-component
cat > templates/app.html.twig <<'END'
{% extends 'layout.html.twig' %}

{% block apps '' %}
<twig:block name="title">
    {{ 'owners'|trans|title }}
</twig:block>
<twig:block name="body">

    <code>{{ app.locale }}</code>
    {% set _sc = 'locale_display' %}
    {{ app.request.locale }}

    <div class="dtsp-verticalContainer row">
        <div class="search-panes col-3">
        </div>
        <div class="col-9">
            {{ block('gridTable') }}
        </div>
    </div>
</twig:block>

<twig:block name="gridTable">

    {{ base_host }}
    {#    {name: 'marking', title: 'marking', browsable: true, order: 0}, #}
    {#   #}
    {% set columns = [
        {name: 'subdomain', title: '*', browsable: false, order: 1, sortable: true},
        {name: 'description', modal: true, browsable: false, order: 4},
        {name: 'locale', title: 'lang', browsable: true, sortable: true, order: 3},
        {name: 'source', title: 'source', browsable: true, modal: true,order: 4, browseOrder:100},
        {name: 'countryCode', title: 'cc', browsable: true, sortable: true, order: 0},
        {name: 'projectCountBin', title: 'log10', browseOrder: 600, browsable: true, order: 0},
        {name: 'projectsWithObjects', title: 'wObj', browseOrder: 600, browsable: true, order: 0},
        {name: 'projectCount', title: '#', browsable: false, browseOrder: 0, sortable: true, order: 1},
        {name: 'meiliObjectCount', title: '##', browsable: false, browseOrder: 0, sortable: true, order: 3},
    ] %}
    <h3>{{ 'owners'|trans|title }}</h3>
    {% set x = base_host|split('.') %}
    {% set global = {
        base_host: base_host,
        host: x[0],
        tld: x[1],
        locale: app.request.locale,
        originalIcon: 'original',
    } %}
    {% set _sc = 'locale_display' %}
    <div {{ stimulus_controller(_sc, {userLocale: app.locale}) }}>

    <twig:api_grid caller="{{ _self }}" class="{{ class }}"

                   columns="{{ columns }}" globals="{{ global }}">
        {#    {% component api_grid with { #}
        {#        caller: _self, #}
        {#        class: class, #}
        {#        columns: columns, #}
        {#        globals: { #}
        {#            locale: app.request.locale #}
        {#        } #}
        {#    } %} #}
        {#        {% block locale %} #}
        {#            {{ row.locale }} #}
        {#        {% endblock %} #}
        <twig:block name="locale" id="x" class="something">
            <span data-locale-display-target="language" data-lang="{{ row.locale }}">{{ row.locale }}</span>
{#            <span data-locale-display-target="country" data-cc="{{row.countryCode }}"></span>#}

        </twig:block>
        {#        {% block locale %} #}
        {#        {% endblock %} #}

        {#        {% block locale %} #}
        {#            {{ row.locale }} #}
        {#        {% endblock %} #}

        <twig:block name="subdomain">
            <div class="modern-way max-12rem text-wrap">
                {% if row.sourceUrl %}
                    <br />
                    <a href="{{ row.sourceUrl }}" title="{{ row.source }}" target="_blank"><span
                                class="{{ globals.originalIcon }}"></span> </a>
                {% endif %}

            </div>
        </twig:block>

            <twig:block name="countryCode">
            {% set flag = row.countryCode %}
            {% if flag %}
                <span data-locale-display-target="language" data-cc="{{ row.countryCode }}"></span>

                <img src="{{ '/bundles/survosvelzon/images/flags/%s.svg'|format(flag) }}" alt="{{ flag }}" height="20" title="{{ row.countryCode  }}"
                     class="rounded"/>
            {% endif %}
        </twig:block>
        {#        {% block countryCode %} #}
        {#            {% set flag = row.countryCode %} #}
        {#            #}{# we don't have the countryName, nor a javascript way to get it, we could create a stimulus controller? Wait for AssetMapper? #}
        {#            {% if flag %} #}
        {#                <img #}
        {#                        src="{{ '/bundles/survosvelzon/images/flags/%s.svg'|format(flag) }}" #}
        {#                        alt="{{ flag  }}" height="20" class="rounded" /> #}
        {#            {% endif %} #}
        {#            #}{# can't do include with embedded twig.  Custom function? #}
        {#            #}{#            {{ include('_partials/flag.html.twig', {flag: row.countryCode}) }} #}
        {#        {% endblock %} #}

        {#        {% block source %} #}
        <twig:block name="source">
            {% set ownerUrl = row.sourceUrl %}
            {% if ownerUrl %}

                <a title="{{ row.source }}" href="{{ ownerUrl }}" target="_blank"><span
                            class="{{ globals.originalIcon }}"></span> {{ row.source }}
                    {{ row.idInSource }}
                    {% set sourceIcon = row.sourceIcon %}
                    {% if sourceIcon %}
                    <img class="favicon" src="{{ sourceIcon }}" alt="{{ row.source }}"/>
                    {% endif %}

                </a>
            {% endif %}

        </twig:block>

        <twig:block name="digmus">

        </twig:block>

        <twig:block name="description">
            {#            TargetLocales: {{ row.targetLocales|join('|') }} #}
            {#            <br />Keys: {{ row.keyedTranslations|keys|json_encode }} #}

            <div class="max-36rem min-12rem">
                <h4 class="text-dark h-3 text-truncate">

                    {% set flag = row.countryCode %}
                    {% if flag %}
                        {#  @todo: expand countryCode to localed country #}
                        <img src="{{ '/bundles/survosvelzon/images/flags/%s.svg'|format(flag) }}" alt="{{ flag }}" title="{{ row.countryCode }}"
                             height="20" class="rounded"/>
                    {% endif %}

{#                    {% set url =  path('owner_in_subdomain', {subdomain: row.subdomain, host: globals.host, tld: globals.tld}) %}#}
{#                    {% set url = url|replace({'http:' : 'https:'}) %}#}
{#                    {% set url = url|trim('/', 'right') %}#}

{#                    {% set url = host_path(globals.base_host, 'owner_show', row.rp) %}#}
                    <a href="{{ path('owner_show', row.rp) }}" target="_blank">
                        {{ row.label|default( row.code) }}
                    </a>
                    <div class="text-muted">
                        {#  https://bobbyhadz.com/blog/javascript-get-country-name-from-country-code#:~:text=Use%20the%20Intl.,Copied! #}
                        <span>
                        {{ row.cityState }}
                        </span>
                        <span data-locale-display-target="country" data-cc="{{ row.countryCode }}"></span>
{#                        <span  data-controller="intl"  data-intl-country-value="{{ row.countryCode|upper }}"#}
{#                              data-intl-user-locale-value="{{ globals.locale }}">{{ row.countryCode|upper }} (name)#}
{#                        </span>#}

                    </div>


{#                    <a href="{{ path('owner_show', row.rp) }}">#}
{#                        {{ row.label|default( row.code) }}#}
{#                    </a>#}
                </h4>

                <p class="line-limit-4 text-wrap">
                    {{ row.description }}
                </p>

            </div>
        </twig:block>

        <twig:block name="name">
            <span class="max-12rem">
                <a href="{{ path('owner_show', row.rp) }}">
                    {{ row.name|default( row.code) }}
                </a>
                <br/><span class="text-tiny" {{ stimulus_target(_sc, 'language') }} data-lang="{{ row.locale }}">{{ row.locale }}</span>
            </span>
        </twig:block>

        {#        {% block code %} #}
        {#            {% set lrp = row.rp|merge({_locale: globals.locale}) %} #}
        {#            <a target="_blank" href="{{ path('project_show', lrp) }}"> #}
        {#                <span class="fas fa-external-link"></span> #}
        {#                <span title="{{ row[field_name] }}" class="d-inline-block text-truncate" style="max-width: 80px;"> #}
        {#                {{ row.name }} - <span class="text-tiny">{{ row.ownerName|default('owner') }}</span> #}
        {#                </span> #}
        {#            </a> #}
        {#        {% endblock %} #}

    </twig:api_grid>

    </div>

    {#    <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">Toggle right offcanvas</button> #}
    {#    <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel"> #}
    {#        <div class="offcanvas-header"> #}
    {#            <h5 id="offcanvasRightLabel">Offcanvas right</h5> #}
    {#            <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button> #}
    {#        </div> #}
    {#        <div class="offcanvas-body"> #}
    {#            DATA HERE #}
    {#        </div> #}
    {#    </div> #}


</twig:block>

END

bin/console lint:twig 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions