I need straightforward solution for dynamically set number of records per page with Knp Pagination Bundle.
I read the this page records per page allow user to choose - codeigniter pagination about dynamically set per page limits and I know I need a drop down with hyperlink inside each item that send a request to server and server use parameter on this request to set limit per page on knp pagination bundle. But I don't know exactly how to handle this actions on server and also and more harder to me how to create items on drop down related to the total number on my query.
my controller:
public function indexAction()
{
$page_title = Util::getFormattedPageTitle("Customers");
$em = $this->get('doctrine.orm.entity_manager');
$dql = "SELECT a FROM CustomersBundle:Customer a WHERE a.enable = 1 ORDER BY a.id";
//$query = $em->createQuery($dql);
//$customers = $query->execute();
$query = $em->createQuery($dql);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1)/*page number*/,
3/*limit per page*/
);
// parameters to template
return $this->render('CustomersBundle:Default:index.html.twig', array(
'page_title' => $page_title,
'pagination' => $pagination,
'image_path' => CustomersConstants::$customers_image_thumb_path
));
}
And my view code is:
{% extends '::base.html.twig' %}
{% block title %}
{{ page_title }}
{% endblock %}
{% block body %}
<h1>
{{ "customers" }}
</h1>
<br />
{% for customer in pagination %}
<a href="{{ customer.url }}" target="_blank">
<div dir="rtl" class="st_simple_box" id="customer{{customer.id}}" >
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="vertical-align: top; width: 115px;">
{% if customer.imageName is not empty %}
<img class="newsimage" src="{{asset(image_path) ~ customer.imageName}}" alt="No Image/>
{% else %}
<img class="newsimage" src="{{asset('images/vakil_default_small.png') ~ customer.imageName}}" alt="No Image"/>
{% endif %}
</td>
<td style="text-align: center;">
<p><span style="font-family: Tahoma;">{{customer.titleFa}}</span></p>
</td>
<td style="text-align: justify;">
<p><span style="font-family: Tahoma;">{{customer.descriptionFa}}</span></p>
</td>
</tr>
</table>
</div>
</a>
{% endfor %}
<div class="navigation">
<span>
{{ knp_pagination_render(pagination) }}
</span>
<!--Here is my drop down html code-->
</div>
<br />
{% endblock %}
**
Edited on 12 March 2014
||||
||||
||||
\\\///
\\//
\/
Is there any way to set MaxItemPerPage on cookie to have a integrated variable and use this variable or change it while Knp Pagination is showed up on twig file.
the answer was correct but because of I used pagination in many bundles to paginate between my entities so I need an integrate variable to change all of them. I use your answer and customize sliding.html.twig on Knp Pagination to reach this code for "customized_sliding.html.twig"
<div class="ui small pagination menu">
<div style="clear: both;">
{% if pageCount > 1 %}
<div class="pagination" style="float: right;">
{% if first is defined and current != first %}
<a href="{{ path(route, query|merge({(pageParameterName): first})) }}" class="small icon item">
<i class="small double angle right icon"></i>
</a>
{% endif %}
{% if previous is defined %}
<a href="{{ path(route, query|merge({(pageParameterName): previous})) }}" class="small icon item">
<i class="small angle right icon"></i>
</a>
{% endif %}
{% for page in pagesInRange %}
{% if page != current %}
<a href="{{ path(route, query|merge({(pageParameterName): page})) }}" class="small item">
{{ page }}
</a>
{% else %}
<a class="small active item">
{{ page }}
</a>
{% endif %}
{% endfor %}
{% if next is defined %}
<a href="{{ path(route, query|merge({(pageParameterName): next})) }}" class="small icon item">
<i class="small angle left icon"></i>
</a>
{% endif %}
{% if last is defined and current != last %}
<a href="{{ path(route, query|merge({(pageParameterName): last})) }}" class="small icon item">
<i class="small double angle left icon"></i>
</a>
{% endif %}
</div>
{% endif %}
<div style="float: left;">
<select name="maxItemPerPage" id="maxItemPerPage">
<option selected="true" style="display:none;">Number Per Page</option>
<option id="10">5</option>
<option id="20">10</option>
<option id="30">20</option>
</select>
</div>
</div>
<script type="text/javascript">
//on select change, you navigate to indexAction and send the parameter maxItemPerPage
$('#maxItemPerPage').change(function(){
{% set currentPath = path(app.request.attributes.get('_route')) %}
var url = "{{path(app.request.attributes.get('_route'),{'maxItemPerPage': '_itemNum'})}}";
var item = $('#maxItemPerPage').find(":selected").text();
jQuery(location).attr('href', url.replace('_itemNum',item ));
});
</script>
</div>
I want to fetch and store MaxItemPerPage from cookie so there is no need to change all bundles code.
For example in my controller I don't know have to fetch the $maxItemPerPage from cookie
$pagination = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1)/*page number*/,
$maxItemPerPage/*limit per page*/
);
And I need change the value of maxItemPerPage on cookie by changing the value of html tag by javascript and redirect the page to same controller and no need to send maxItemPerPage to controller.
This can be done easily (if i understood well)
public function indexAction($maxItemPerPage=20)
{
$page_title = Util::getFormattedPageTitle("Customers");
$em = $this->get('doctrine.orm.entity_manager');
$dql = "SELECT a FROM CustomersBundle:Customer a WHERE a.enable = 1 ORDER BY a.id";
//$query = $em->createQuery($dql);
//$customers = $query->execute();
$query = $em->createQuery($dql);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1)/*page number*/,
$maxItemPerPage /*limit per page*/
);
// parameters to template
return $this->render('CustomersBundle:Default:index.html.twig', array(
'page_title' => $page_title,
'pagination' => $pagination,
'image_path' => CustomersConstants::$customers_image_thumb_path
));
}
in the view
{% extends '::base.html.twig' %}
{% block title %}
{{ page_title }}
{% endblock %}
{% block javascript%}
<script type="text/javascript">
//on select change, you navigate to indexAction and send the parameter maxItemPerPage
$('#maxItemPerPage').change(function(){
var url = '{{path('controller_index_route','maxItemPerPage':_itemNum)}}';
var item = $('#maxItemPerPage').find(":selected").text();
window.location.href = url.replace('_itemNum',item );
})
</script>
{% endblock %}
{% block body %}
<h1>
{{ "customers" }}
</h1>
<br />
{% for customer in pagination %}
<a href="{{ customer.url }}" target="_blank">
<div dir="rtl" class="st_simple_box" id="customer{{customer.id}}" >
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="vertical-align: top; width: 115px;">
{% if customer.imageName is not empty %}
<img class="newsimage" src="{{asset(image_path) ~ customer.imageName}}" alt="No Image/>
{% else %}
<img class="newsimage" src="{{asset('images/vakil_default_small.png') ~ customer.imageName}}" alt="No Image"/>
{% endif %}
</td>
<td style="text-align: center;">
<p><span style="font-family: Tahoma;">{{customer.titleFa}}</span></p>
</td>
<td style="text-align: justify;">
<p><span style="font-family: Tahoma;">{{customer.descriptionFa}}</span></p>
</td>
</tr>
</table>
</div>
</a>
{% endfor %}
<div class="navigation">
<span>
{{ knp_pagination_render(pagination) }}
</span>
<!--Here is my drop down html code-->
</div>
<br />
<select name="maxItemPerPage" id="maxItemPerPage">
<option id="10">10</option>
<option id="20">20</option>
<option id="30">30</option>
</select>
{% endblock %}
Related
I've been working on an online learning website for a school project. I've had trouble passing variales when clicking on a lesson, belonging to a section, inside a course. The idea is that on a course page (formation.html.twig), there's a summary of the course, and you can click on the lessons which are in a sidebar menu. It should then display a page with the same menu, and the content of the lesson showing in place of the course summary (lesson.html.twig).
I've updated the controller so the url goes:
formations/consulter-formationid-sectionid-lessonid
In the view, I wrote {{ path('app_formations_lesson', {'formation':formation.id, 'section': section.id, 'id':lesson.id}) }}
It's working alright for the url and the right values show when I click, but the page refreshes and won't load the right twig view (lesson.html.twig), it loads the same view I'm currently on (formation.html.twig).
FormationsController:
#[Route('/formations/consulter-{id}', name: 'app_formations_see')]
public function see($id): Response
{
$formation = $this->doctrine->getRepository(Formation::class)->findOneById($id);
$section = $this->doctrine->getRepository(Section::class)->findAll();
$lesson = $this->doctrine->getRepository(Lesson::class)->findAll();
return $this->render('formations/formation.html.twig', [
'formation' => $formation,
'sections' => $section,
'lessons' => $lesson
]);
}
#[Route('/formations/consulter-{formation}-{section}-{id}', name: 'app_formations_lesson')]
public function seeLesson($id): Response
{
$lesson = $this->doctrine->getRepository(Lesson::class)->findOneById($id);
return $this->render('formations/lesson.html.twig', [
'lesson' => $lesson
]);
}
formation.html.twig
{% extends 'base.html.twig' %}
{% block title %}{{ formation.title }}{% endblock %}
{% block content %}
<div class="formationcontainer text-center">
{% block sidebar %}
{% include "./formations/sidebar.html.twig" %}
{% endblock %}
<h1>{{ formation.title }} par {{ formation.user.firstname }} {{ formation.user.lastname }}</h1>
{{ formation.description }}
<hr>
<h2>Sommaire</h2>
<div class="tableau">
<table class="table">
{% for section in formation.sections %}
<thead class="table-success">
<tr>
<th scope="col">{{ section.name }}</th>
</tr>
</thead>
<tbody>
{% for lesson in section.lessons %}
<tr>
<td>{{ lesson.title }}</td>
</tr>
{% endfor %}
</tbody>
{% endfor %}
</table>
</div>
</div>
{% endblock %}
lesson.html.twig
{% extends 'base.html.twig' %}
{% block title %}titre de la leçon{% endblock %}
{% block content %}
<div class="formationcontainer text-center">
{% block sidebar %}
{% include "./formations/sidebar.html.twig" %}
{% endblock %}
<h1>Nom de la leçon</h1>
<hr>
<h2>Vidéo</h2>
<h2>Contenu</h2>
</div>
{% endblock %}
sidebar block
<!-- Sidear for lesson pages -->
<nav class="flex-shrink-0flex-shrink-0 p-3 bg-white sidenav">
<button class="btn btn-success" id="sidenav-btn" type="button" data-bs-toggle="collapse" data-bs-target="#sidebarCollapse" aria-expanded="false" aria-controls="collapseOne">
Sommaire
</button>
<div class="list-unstyled ps-0 ul-custom navbar-collapse collapse show" id="sidebarCollapse" aria-expanded="true">
<li class="mb-1">
{% for section in formation.sections %}
<ul class="list-unstyled align-items-center rounded fw-normal">
<li>{{ section.name }}</li>
</ul>
<div>
{% for lesson in lessons %}
<ul class="list-unstyled fw-normal pb-1 small">
<li>{{ lesson.title }}</li>
</ul>
{% endfor %}
</div>
{% endfor %}
</li>
<li class="border-top my-3"></li>
<li class="mb-1">
<ul class="list-unstyled fw-normal pb-1 small">
<li>retour à la liste des formations</li>
</ul>
</li>
</div>
</nav>
Where does this issue come from? How can I display the right view?
Thanks a lot!
edit: I swapped the code in the controller to match the seeLesson function first.
#[Route('/formations/consulter-{formation}-{section}-{id}', name: 'app_formations_lesson')]
public function seeLesson($id): Response
{
$formation = $this->doctrine->getRepository(Formation::class)->findOneById($id);
$section = $this->doctrine->getRepository(Section::class)->findAll();
$lesson = $this->doctrine->getRepository(Lesson::class)->findOneById($id);
return $this->render('formations/lesson.html.twig', [
'lesson' => $lesson,
'formation' => $formation,
'sections' => $section
]);
}
#[Route('/formations/consulter-{id}', name: 'app_formations_see')]
public function see($id): Response
{
$formation = $this->doctrine->getRepository(Formation::class)->findOneById($id);
$section = $this->doctrine->getRepository(Section::class)->findAll();
$lesson = $this->doctrine->getRepository(Lesson::class)->findAll();
return $this->render('formations/formation.html.twig', [
'formation' => $formation,
'sections' => $section,
'lessons' => $lesson
]);
}
It's rendering the wrong page because your URLs are too similar.
When trying to determine what method to execute, Symfony matches the requested URL against the route definitions above the controller methods from top to bottom.
If you're requesting for example /formations/consulter-1-2-3,
Symfony first tries to match this against /formations/consulter-{id}.
This matches if you substitute 1-2-3 for {id}, so it executes the see method.
To fix you have two options:
Either switch the order of the 2 methods in your controller so that the method seeLesson is defined above the see method. Symfony will then first try to match against the route for the seeLesson method.
Or keep the method order as is, but add a constraint to the {id} parameter in the route for the see method, to specify that the matched {id} can only consist of digits:
#[Route('/formations/consulter-{id}', name: 'app_formations_see', requirements: ['id' => '\d+'])]
I work with Symfony and Twig. I currently have a twig page containing a list of products, I display them with a foreach loop and I put pagination to limit the display of products.
I'm trying to put a form in this page with a checkbox as input and my problem is the following:
the checkboxes appear on all the products on the first page but when I go to the second page, I don't see the checkboxes, I need to reload the page to see them.
there is some code :
view of my loop :
<form>
<div class="row" >
{% for annonce in annonces %}
<div class="col-12 col-md-6 col-lg-4">
<p class="text text--blue text--bold m-0 text--medium mt-2">
{{ annonce._source.titre }}
</p>
<p class="m-0">{{ 'Réf' }}: {{ annonce._source.reference }}</p>
<div class="d-flex mt-2 text--bold">
<div class="d-flex me-2">
{{ annonce._source.ville }}
</div>
</div>
<div>
<input type="checkbox" name="checkbox[]" id="checkbox_pdf" value="{{annonce._id}}" multiple/>
</div>
</div>
{% endfor %}
</div>
<input type="submit" id="pdf_submit" value="Create PDF" name="submit_pdf" class="btn btn-primary">
</form>
view of the pagination :
<div class="col d-flex justify-content-between align-items-center">
<div class="d-flex">
{% if page > 0 %}
<a href="#" data-action="pagination" data-uri="{{ path('ajax_annonce_pagination',{'page':0, 'type':'frontoffice'}) }}" data-target="pagination-target">
«
</a>
<a href="#" data-action="pagination" data-uri="{{ path('ajax_annonce_pagination',{'page':page-1, 'type':'frontoffice'}) }}" data-target="pagination-target">
{{ 'Précédent' }}
</a>
{% else %}
<a href="#" disabled="disabled" >
{{ 'Précédent' }}
</a>
{% endif %}
</div>
<div>
<ul class="list-unstyled pagination m-0">
{% for i in (page+1)..(page+4) %}
{% if i <= numberOfMaxPage %}
{% if i == (page+1) %}
<li>
<a href="#" data-action="pagination" data-uri="{{ path('ajax_annonce_pagination',{'page':(i-1), 'type':'frontoffice'}) }}" data-target="pagination-target">
{{ i }}
</a>
</li>
{% else %}
<li>
<a href="#" data-action="pagination" data-uri="{{ path('ajax_annonce_pagination',{'page':(i-1), 'type':'frontoffice'}) }}" data-target="pagination-target">
{{ i }}
</a>
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
</div>
<div class="d-flex">
{% if page < (numberOfMaxPage-1) %}
<a href="#" data-action="pagination" data-uri="{{ path('ajax_annonce_pagination',{'page':page+1, 'type':'frontoffice'}) }}" data-target="pagination-target">
{{ 'Suivant' }}
</a>
<a href="#" data-action="pagination" data-uri="{{ path('ajax_annonce_pagination',{'page':numberOfMaxPage-1, 'type':'frontoffice'}) }}" data-target="pagination-target">
»
</a>
{% endif %}
</div>
</div>
JS of the pagination :
$( document ).ready(function() {
$(document).on('click', 'a.pagination',function(e) {
e.preventDefault();
$.ajax({
url: $(this).data('uri'),
}).done(function(html) {
$('#pagination-target').html(html);
$('html,body').animate({scrollTop: $('#pagination-target').offset().top - 80}, 200);
var $scrollable = document.getElementById('pagination-target');
$scrollable.scrollIntoView();
});
});
});
In my controller I render my view like this :
return $this->render('front/annonce/list.html.twig', array(
'annonces' => $results['hits']['hits'],
'total' => $results['hits']['total']['value'],
'website' => $website,
'page' => $request->query->getInt('page')
));
What is this problem related to? is this due to the fact that it is not possible to add inputs in a looped element?
Is it related to pagination?
thanks you in advance
Basically in their shopping cart I would like to display the image they upload to print but i can't seem to figure it out..... I know i need to add in something along the lines of <img src="http://path/to/thumbnails/myimage.jpg"> but i don't know what to add in place of "http://path/to/thumbnails/myimage.jpg" within this code to display the image they upload if there even is anything? All help appreciated! Thanks (sorry if this is a silly question and plain obvious)
{% comment %}
This is your /cart template. If you are using the Ajaxify Cart plugin,
your form (with action="/cart") layout will be used in the drawer/modal.
For info on test orders:
- General http://docs.shopify.com/manual/your-store/orders/test-orders
- Shopify Payments - http://docs.shopify.com/manual/more/shopify-payments/testing-shopify-payments
<!-- Bold: Options 4-1 -->
<script>function update_qty_builder(builder_id, qty){ jQuery('.'+builder_id+"_qty").val(qty.value); } function remove_product_builder(builder_id){ jQuery('.'+builder_id+"_qty").val(0); jQuery('.'+builder_id+"_qty").parents("form").submit(); }</script>
{% include 'bold-cart-handler' %}
<!-- // end Options 4-1 -->
{% endcomment %}
{% if cart.item_count > 0 %}
<form action="/cart" method="post" novalidate class="cart">
<div class="section-header">
<h1 class="section-header__title">{{ 'cart.general.title' | t }}</h1>
</div>
<div class="cart__row medium-down--hide cart__header-labels">
<div class="grid--full">
<div class="grid__item large--one-half push--large--one-half">
<div class="grid--full">
<div class="grid__item one-third medium-down--one-third">
<span class="h4">{{ 'cart.label.price' | t }}</span>
</div>
<div class="grid__item one-third medium-down--one-third text-center">
<span class="h4">{{ 'cart.label.quantity' | t }}</span>
</div>
<div class="grid__item one-third medium-down--one-third text-right">
<span class="h4">{{ 'cart.label.total' | t }}</span>
</div>
</div>
</div>
</div>
</div>
{% comment %}
Loop through products in the cart
{% endcomment %}
{% for item in cart.items %}
<!-- Bold: Options 4-2 -->
{% include 'boldoptions' with 'step2' %}
<!-- // end Options 4-2 -->
<tr style="{% include 'boldoptions' with 'step4' %}" class="{% include 'boldoptions' with 'step3' %}">
<div class="cart__row" data-id="{{ item.id }}">
<div class="grid--full cart__row--table-large">
<div class="grid__item large--one-half">
<div class="grid">
<div class="grid__item one-third">
<a href="{{ item.url | within: collections.all }}" class="cart__image">
{% comment %}
More image size options at:
- http://docs.shopify.com/themes/filters/product-img-url
{% endcomment %}
<!-- Bold: Options 4-5 -->
{% if builder[0] %}
<img src="{{ builder[1] }}" alt="{{ builder[0] }}" />
{% else %}
<img src="{{ item | img_url: 'medium' }}" alt="{{ item.title | escape }}">
</a>
<!-- Bold: Options 4-6 -->
{% include 'boldoptions' with 'step6' %}
<!-- // end Options 4-6 -->
{% endif %}
<!-- // end Options 4-5 -->
</div>
<div class="grid__item two-thirds">
<a href="{{ item.url }}" class="h4">
{{ item.product.title }}
</a>
{% unless item.variant.title contains 'Default' %}
<br>
<small>{{ item.variant.title }}</small>
{% endunless %}
{% if settings.cart_vendor_enable %}
<p>{{ item.vendor }}</p>
{% endif %}
{% comment %}
Optional, loop through custom product line items if available
For more info on line item properties, visit:
- http://docs.shopify.com/support/your-store/products/how-do-I-collect-additional-information-on-the-product-page-Like-for-a-monogram-engraving-or-customization
{% endcomment %}
{% include 'product_customizer_cart' %}
{% if item.properties.size > 0 %}
{% for p in item.properties %}
{% unless p.last == blank %}
{{ p.first }}:
{% comment %}
Check if there was an uploaded file associated
{% endcomment %}
{% if p.last contains '/uploads/' %}
{{ p.last | split: '/' | last }}
{% else %}
{{ p.last }}
{% endif %}
<br>
{% endunless %}
{% endfor %}
{% endif %}
<a href="{% include 'boldoptions' with 'step9' %}" data-id="{{ item.id }}" class="{% include 'boldoptions' with 'step10' %} cart__remove" {% include 'boldoptions' with 'step11' %}>
<small>{{ 'cart.general.remove' | t }}</small>
</a>
</div>
</div>
</div>
<div class="grid__item large--one-half">
<div class="grid--full cart__row--table-large">
<div class="grid__item one-third">
<span class="cart__mini-labels">{{ 'cart.label.price' | t }}</span>
<span class="h5">{% include 'boldoptions' with 'step12' %}</span>
</div>
<div class="grid__item one-third text-center">
<span class="cart__mini-labels">{{ 'cart.label.quantity' | t }}</span>
{% comment %}
Added data-id for the ajax cart implementation only.
{% endcomment %}
<input type="number" name="updates[]" id="updates_{{ item.id }}" class="{% include 'boldoptions' with 'step7' %}" value="{{ item.quantity }}" min="0" data-id="{{ item.id }}" {% include 'boldoptions' with 'step8' %}>
</div>
<div class="grid__item one-third text-right">
<span class="cart__mini-labels">{{ 'cart.label.total' | t }}</span>
<span class="h5">{% include 'boldoptions' with 'step13' %}</span>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
<div class="cart__row">
<div class="grid">
{% comment %}
Optional, add a textarea for special notes
- Your theme settings can turn this on or off. Default is on.
- Make sure you have name="note" for the message to be submitted properly
{% endcomment %}
{% if settings.cart_notes_enable %}
{% assign noteSize = cart.note | size %}
<div class="grid__item large--five-twelfths">
<button type="button" class="text-link cart__note-add{% if noteSize > 0 %} is-hidden{% endif %}">
{{ 'cart.label.add_note' | t }}
</button>
<div class="cart__note{% if noteSize > 0 %} is-active{% endif %}">
<label for="CartSpecialInstructions">{{ 'cart.general.note' | t }}</label>
<textarea name="note" class="input-full" id="CartSpecialInstructions">{{ cart.note }}</textarea>
</div>
</div>
{% endif %}
<div class="grid__item text-right{% if settings.cart_notes_enable %} large--seven-twelfths{% endif %}">
<p>
<span class="cart__subtotal-title">{{ 'cart.general.subtotal' | t }}</span>
<span class="h5 cart__subtotal">{{ cart.total_price | money }}</span>
</p>
<p><em>{{ 'cart.general.shipping_at_checkout' | t }}</em></p>
<input type="submit" name="update" class="btn--secondary update-cart" value="{{ 'cart.general.update' | t }}">
<input type="submit" name="checkout" class="btn" value="{{ 'cart.general.checkout' | t }}">
{% if additional_checkout_buttons %}
<div class="cart__additional_checkout">{{ content_for_additional_checkout_buttons }}</div>
{% endif %}
</div>
</div>
</div>
</form>
{% else %}
{% comment %}
The cart is empty
{% endcomment %}
<h2>{{ 'cart.general.title' | t }}</h2>
<p>{{ 'cart.general.empty' | t }}</p>
<p>{{ 'cart.general.continue_browsing_html' | t }}</p>
{% endif %}
<!-- Bold: Options 4-14 -->
{% include 'bold-cart-modal' %}
<!-- // end Options 4-14 -->
You have to include the full publicly reachable image path in the src attribute of the image tag
<img src="http://path/to/thumbnails/myimage.jpg">
I have 2 Entities: Clinic, Vet, for which I created CRUD templates with app/console generate:doctrine:crud
I first created the Clinic entity and created my "admin template" in AgriHealth/AhpBundle/Resources/views/admin.html.twig and then extend this in
AgriHealth/AhpBundle/Resources/views/Clinic/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
This worked.
Then I created Entity Vet and ran the crud generator. Again I'm extending:
AgriHealth/AhpBundle/Resources/views/Vet/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
But this seems to be ignored, as the layout from my admin template doesn't come through. I have tried:
app/console cache:clear
renaming admin.html.twig: causes an error in both views as expected
I must be missing something? Any ideas?
Twig code below:
src/AgriHealth/AhpBundle/Resources/views/admin.html.twig
{% extends '::base.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<link href="{{ asset('bundles/agrihealthahp/css/admin.css') }}" rel="stylesheet" />
<link href="{{ asset('bundles/agrihealthsecurity/css/admin.css') }}" rel="stylesheet" />
{% endblock %}
{% block body -%}
<div class="row" id="header">
<div class="small-12 columns">
<h1><a href=""><img src="/bundles/agrihealthahp/images/agrihealth-logo.png" />
<span>Animal Health Planner</span></a></h1>
</div>
</div>
<div class="row" id="menu">
<div class="small-12 columns">
</div>
</div>
<div class="row" id="content">
<div class="small-12 columns">
{% block admin %}{% endblock %}
</div>
</div>
<div class="row" id="black_footer">
<div class="small-12 medium-5 columns footer-black-1">
<div class="moduletable">
<div class="custom">
<p>www.agrihealth.co.nz</p></div>
</div>
</div>
<div class="small-12 medium-7 columns ">
<div class="left footer-black-2">
<div class="moduletable">
<div class="custom">
<p>0800 821 421</p></div>
</div>
</div>
<div class="right footer-black-3">
<div class="moduletable">
<div class="custom">
<p><sup></sup><sup><img style="line-height: 1.1;" src="/bundles/agrihealthahp/images/agrihealth_white.png" alt="agrihealth white"></sup></p></div>
</div>
</div>
</div>
</div>
{% endblock %}
src/AgriHealth/AhpBundle/Resources/views/Clinic/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
{% block admin -%}
<h1>Clinics</h1>
<ul class="actions">
<li>
<a href="{{ path('clinic_new') }}">
Add Clinic
</a>
</li>
</ul>
<table class="records_list">
<thead>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Fax</th>
<th>After Hours</th>
<th>Email</th>
<th></th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td>{{ entity.name }}</td>
<td>{{ entity.phone }}</td>
<td>{{ entity.fax }}</td>
<td>{{ entity.afterhours }}</td>
<td>{{ entity.email }}</td>
<td>
<ul class="actions">
<li>
edit
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
src/AgriHealth/AhpBundle/Resources/views/Vet/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
{% block body -%}
<h1>Vets</h1>
<ul class="actions">
<li>
<a href="{{ path('vet_new') }}">
Add Vet
</a>
</li>
</ul>
<table class="records_list">
<thead>
<tr>
<th>Name</th>
<th>Mobile</th>
<th>Clinic</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('vet_edit', { 'id': entity.id }) }}">{{ entity.firstname }} {{ entity.lastname }}</td>
<td>{{ entity.mobile }}</td>
<td>{{ entity.clinic }}</td>
<td>
<ul class="actions">
<li>
edit
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
Check the source of the page for the stylesheets included in admin.html.twig.
If they are there, the problem is that you are overriding your body block.
Change
src/AgriHealth/AhpBundle/Resources/views/Vet/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
{% block body -%}
to
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
{% block admin -%}
If your stylesheets are not in the page there must be another problem .
I have a homepage wich dynamically loads a bunch of "posts" (similar to facebook wall).
There is the option to follow a post, but when someone clicks on the follow button, which has a counter on following people, I need to reload all the homepage to update this value. How can I update just the part corresponding to the post? Actually the post is in an extern hmtl.twig file which I render from the homepage code:
<div class="row">
<div class="col-md-6">
{% for sueno in suenos %}
{% if loop.index0 is even %}
{{ render(controller('SuenoBundle:Default:suenoFrontend', { 'sueno': sueno } )) }}
{% endif %}
{% endfor %}
</div><!--/col-md-6-->
This is the controller:
public function suenoFrontendAction($sueno)
{
return $this->render('SuenoBundle:Default:suenoFrontend.html.twig', array(
'sueno' => $sueno));
}
This the post html file:
<h4 class="text-center nombre-usuario">{{ sueno.usuario.nombre ~ ' ' ~ sueno.usuario.apellido }}</h4>
{% if sueno.necesitaAyuda == 1 %}
<p class="text-center texto-sueno"><img src="{{ asset('bundles/estructura/images/SOS.png') }}" width="25" height="25" alt="SOS" /></p>
{% endif %}
{% if sueno.rol == 'foto' %}
<img src="{{ asset('upload/images/' ~ sueno.fotoLink) }}" class="img-responsive img-thumbnail" alt="Responsive image">
{% elseif sueno.rol == 'video' %}
<div class="video-container"><iframe src="{{ sueno.linkVideo }}" frameborder="0" allowfullscreen=""></iframe></div>
{% endif %}
<h4 class="text-center titulo-sueno">{{ sueno.titulo }}</h4>
<h4 class="text-center quepido-sueno">{{ sueno.quePido }}</h4>
<p class="text-center texto-sueno info">{{ sueno.texto }}</p>
<br>
<div>
{% set size = sueno.usuariosColaboradores | length %}
{% set size2 = sueno.usuariosSeguidores | length %}
<p class="text-center opciones-sueno">
<img src="{{ asset('bundles/estructura/images/colaboradores.png') }}" width="20" height="20" alt="Colaboradores" /> {{ size }}
<img src="{{ asset('bundles/estructura/images/punto.png') }}" width="5" height="5" alt="punto" />
<img src="{{ asset('bundles/estructura/images/seguidores.png') }}" width="20" height="20" alt="Seguidores" /> {{ size2 }}
<img src="{{ asset('bundles/estructura/images/punto.png') }}" width="5" height="5" alt="punto" />
<img src="{{ asset('bundles/estructura/images/compartir.png') }}" width="20" height="20" alt="Compartir" />
</p>
</div>
<hr>
Here you can see the action correpsonding to follow a post(its in the previous code, I remark the line):
<img src="{{ asset('bundles/estructura/images/seguidores.png') }}" width="20" height="20" alt="Seguidores" /> {{ size2 }}
size2 value is the one to update. the controller called when clicking here is this(and where I suppose the failure is):
public function seguirAction($suenoid)
{
$em = $this->getDoctrine()->getManager();
$usuario = $this->getUser();
$sueno = $em->getRepository('SuenoBundle:Sueno')->findOneBy(array('id' => $suenoid));
$usuario->getSuenosSigue()->add($sueno);
$em->persist($usuario);
$em->flush();
// $suenos = $em->getRepository('SuenoBundle:Sueno')->findBy(array('usuario' => $usuario->getId()));
//esto hay que cambiarlo entero para conseguir los sueños apropiados
//return $this->render('EstructuraBundle:Home:home.html.twig', array('suenos'=> $suenos , 'usuario' => $usuario));
return $this->render('SuenoBundle:Default:suenoFrontend.html.twig', array(
'sueno' => $sueno));
}
The thing is that when this render happens, the post fills the full page.
What I want is just to re-render this post in the homepage