Display list action on the top and the bottom of the result list

95 views
Skip to first unread message

hel...@touscoprod.com

unread,
Jan 27, 2014, 8:51:51 AM1/27/14
to symfony2adm...@googlegroups.com
Hi,

I am new in SF2 and admingenerator, I try to display the action list bar twice but I fail.

I created a block named list_actions wich contains the code from resultsBuilderTemplate :

{% use 'paginator.php.twig' %}
{% use 'generic_actions.php.twig' %}
{% use 'batch_actions.php.twig' %}

{{ block('list_actions') }}
    <div class="form-actions list-actions">
        {% if batch_actions is defined and batch_actions|length > 0 %}
            <div id="batch_actions" class="pull-left btn-toolbar">
                {{ block('batch_actions') }}
            </div>
        {% endif -%}

        {% if actions is defined and actions|length > 0 %}
            <div id="generic_actions" class="pull-left btn-toolbar">
                {{ block('generic_actions') -}}
            </div>
        {% endif -%}

            <div class="pull-right btn-toolbar">
                {{- block('list_paginator_perpage') -}}
            </div>

            <div class="pull-right btn-toolbar">
                {{- block('list_paginator_pages') -}}
            </div>
    </div>
{{ block('list_actions') }}


and then, in resultsBuilderTemplate I try to display it twice like that :

{% use 'nbresults.php.twig' %}
{% use 'thead.php.twig' %}
{% use 'tbody.php.twig' %}
{% use 'list_actions.php.twig' %}

{% block list_results %}
<div class="results-list">
   
    {{- block('list_nbresults') -}}
   
    {{- block('list_actions') -}}

    {{- block('form_batch_actions') }}
    <div id="list_result_admingenerator">
        <table id="table-list-{{ builder.ModelClass }}" class="table table-striped table-hover table-condensed object-actions-{{ builder.ModelClass }}">
            {{ block('list_thead') -}}
            {{- block('list_tbody') }}
        </table>
    </div>
   
    {{- block('list_actions') -}}
        {{- block('endform_batch_actions') }}
</div>
{% endblock list_results %}


But I have the error :Template "list_actions.php.twig" cannot be used as a trait in "List/ResultsBuilderTemplate.php.twig".I do not understand what the problem is.

What am I doing wrong ?

Cédric Lombardot

unread,
Jan 27, 2014, 9:31:42 AM1/27/14
to Symfony2 Admingenerator bundles support for users
Hello,

Your list_action is space : {{ block('list_actions') }} should be a
block declaration ! You can only use traits twigs wich are blocks


eg :

my_pagination.php.twig :

{% block do_my_pagination %}
HERE IS THE WORLD
{% endblock %}

my_main_twig.php.twig


{% use "my_pagination.php.twig" %}

{% block body %}
{{ block('do_my_pagination') }}

....

{{ block('do_my_pagination') }}
{% endblock %}

Cedric

2014-01-27 <hel...@touscoprod.com>:
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Symfony2 Admingenerator bundles support for users" group.
> To post to this group, send email to
> symfony2adm...@googlegroups.com
> To unsubscribe from this group, send email to
> symfony2admingene...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony2admingenerator?hl=en
>
> ---
> Found bundle documentation at http://symfony2admingenerator.org/
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Symfony2 Admingenerator bundles support for users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to symfony2admingene...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

hel...@touscoprod.com

unread,
Jan 27, 2014, 9:46:10 AM1/27/14
to symfony2adm...@googlegroups.com
I have changed my template, now I have this error :

The block 'list_paginator_perpage' has already been defined line 19 in Admingenerated/MyBundle/Resources/views/UserList/results.html.twig at line 313

alex baron

unread,
Jan 27, 2014, 10:00:26 AM1/27/14
to symfony2adm...@googlegroups.com
you can't use a block twice in a same view. May be you can use include statement.

Alexandre Baron
port : 06.70.71.64.36
tel   : 02.40.71.84.04


I have changed my template, now I have this error :

The block 'list_paginator_perpage' has already been defined line 19 in Admingenerated/MyBundle/Resources/views/UserList/results.html.twig at line 313

--

Cédric Lombardot

unread,
Jan 27, 2014, 10:42:01 AM1/27/14
to Symfony2 Admingenerator bundles support for users
Oups of course ! Or you can use :

{% use "blocks.html" with sidebar as parent_sidebar %}
http://twig.sensiolabs.org/doc/tags/use.html

2014-01-27 alex baron <alexb...@gmail.com>:
Message has been deleted

hel...@touscoprod.com

unread,
Jan 27, 2014, 11:08:37 AM1/27/14
to symfony2adm...@googlegroups.com
I try this :

{% use 'nbresults.php.twig' %}
{% use 'thead.php.twig' %}
{% use 'tbody.php.twig' %}
{% use 'batch_actions.php.twig' %}
{% use 'list_actions.php.twig' with list_actions as list_actions_top %}
{% use 'list_actions.php.twig' with list_actions as list_actions_bot %}



{% block list_results %}
    <div class="results-list">

        {{- block('list_nbresults') -}}

        {{- block('list_actions_top') -}}


        {{- block('form_batch_actions') }}
            <div id="list_result_admingenerator">  
                <table id="table-list-{{ builder.ModelClass }}" class="table table-striped table-hover table-condensed object-actions-{{ builder.ModelClass }}">
                    {{ block('list_thead') -}}
                    {{- block('list_tbody') }}
                </table>
            </div>

            {{- block('list_actions_bot') -}}


        {{- block('endform_batch_actions') }}
    </div>
{% endblock list_results %}


But I have this error : The block 'generic_actions' has already been defined line 19 in Admingenerated/MyBundle/Resources/views/UserList/results.html.twig at line 337

So I change my list_actions template like that :
{% use 'paginator.php.twig' %}
{% use 'generic_actions.php.twig' with generic_actions as test %}
{% use 'batch_actions.php.twig' %}

{%  block list_actions %}

    <div class="form-actions list-actions">
        {% if batch_actions is defined and batch_actions|length > 0 %}
            <div id="batch_actions" class="pull-left btn-toolbar">
                {{ block('batch_actions') }}
            </div>
        {% endif -%}

        {% if actions is defined and actions|length > 0 %}
            <div id="generic_actions" class="pull-left btn-toolbar">
                {{ block('test') -}}

            </div>
        {% endif -%}

            <div class="pull-right btn-toolbar">
                {{- block('list_paginator_perpage') -}}
            </div>

            <div class="pull-right btn-toolbar">
                {{- block('list_paginator_pages') -}}
            </div>
    </div>
{% endblock %} 

But I still have the error with generic_actions bloc.

Can you provide me a solution to display the actions and paginator twice please ?
Reply all
Reply to author
Forward
0 new messages