Question

I need just to display the first 24 lines of records in entities; so that in the second column (lun) it shows first 24 records and in the third one (mardi) it shows next 24 records and so on

<table width="80%" border="1" cellpadding="0" cellspacing="0">
    <thead>
        <tr style=" width:100%;">
            <th>&nbsp;&nbsp;</th>
            <th>lun</th>
            <th>mardi</th>
            <th>mercredi</th>
            <th>jeudi</th>
            <th>vendredi</th>
            <th>Samedi</th>
        </tr>
    </thead>
    <tbody>
        {% for entity in entities %}
            <tr>
                <td><a href="">{{ entity.id }}</a></td>
            </tr>
        {% endfor %}
    </tbody>
</table>

Can someone help me to fix this issue
Here is the code in my controller:

$entities = $em->getRepository('PublishDemandsBundle:Appointement')->findBy(array('therapist'=>$user));
Was it helpful?

Solution

Not sure I understood what you want, but try this:

<table width="80%" border="1" cellpadding="0" cellspacing="0">
    <thead>
        <tr style=" width:100%;">
            <th>&nbsp;&nbsp;</th>
            <th>lun</th>
            <th>mardi</th>
            <th>mercredi</th>
            <th>jeudi</th>
            <th>vendredi</th>
            <th>Samedi</th>
        </tr>
    </thead>
    <tbody>
        {% for i in 0..23) %}
            <tr>
                <td></td>
                <td><a href="">{{ entities[i].id }}</a></td>
                <td><a href="">{{ entities[i+24].id }}</a></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>                    
            </tr>
        {% endfor %}
    </tbody>
</table>

OTHER TIPS

First of all you need to pass the array of objects of your entity through controller to the twig file

$entities = $em->getRepository('PublishDemandsBundle:Appointement')->findBy(array('therapist'=>$user));
return $this->render('PublishDemandsBundle:Default:myTemplateName.html.twig', array(
    'entities' => $entities
));

Now in your twig file you can apply following logic:

<table width="80%" border="1" cellpadding="0" cellspacing="0">
<thead>
    <tr style=" width:100%;">
        <th>&nbsp;&nbsp;</th>
        <th>lun</th>
        <th>mardi</th>
        <th>mercredi</th>
        <th>jeudi</th>
        <th>vendredi</th>
        <th>Samedi</th>
    </tr>
</thead>
<tbody>
    {% for entity in entities if loop.index < 24 %}
        <tr>
            <td>&nbsp;&nbsp;</td>
            {% for i in 1..6 %}
            <td>
               {% if entities[loop.parent.loop.index0 + (loop.index0 * 24)] is defined %}
               <a href="">{{ entities[loop.parent.loop.index0 + (loop.index0 * 24)].id }}</a>
               {% endif %}
            </td>
            {% endfor %}
        </tr>
    {% endfor %}
</tbody>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top