new
new
Esta aplicación demo ha sido programada con el framework Symfony para mostrar la forma recomendada de programar aplicaciones Symfony.
Para más información, consulta la documentación de Symfony.
Pulsa este botón para ver el código fuente del controlador y de la plantilla utilizados para crear esta página.
src/Controller/BlogController.php at line 52
/**
* NOTE: For standard formats, Symfony will also automatically choose the best
* Content-Type header for the response.
*
* See https://symfony.com/doc/current/routing.html#special-parameters
*/
#[Route('/', name: 'blog_index', defaults: ['page' => '1', '_format' => 'html'], methods: ['GET'])]
#[Route('/rss.xml', name: 'blog_rss', defaults: ['page' => '1', '_format' => 'xml'], methods: ['GET'])]
#[Route('/page/{page}', name: 'blog_index_paginated', defaults: ['_format' => 'html'], requirements: ['page' => Requirement::POSITIVE_INT], methods: ['GET'])]
#[Cache(smaxage: 10)]
public function index(Request $request, int $page, string $_format, PostRepository $posts, TagRepository $tags): Response
{
$tag = null;
if ($request->query->has('tag')) {
$tag = $tags->findOneBy(['name' => $request->query->get('tag')]);
}
$latestPosts = $posts->findLatest($page, $tag);
// Every template name also has two extensions that specify the format and
// engine for that template.
// See https://symfony.com/doc/current/templates.html#template-naming
return $this->render('blog/index.'.$_format.'.twig', [
'paginator' => $latestPosts,
'tagName' => $tag?->getName(),
]);
}
templates/blog/index.html.twig at line 1
{% extends 'base.html.twig' %}
{% block body_id 'blog_index' %}
{% block main %}
{% for post in paginator.results %}
{{ include('blog/_post.html.twig') }}
{% else %}
<div class="jumbotron">{{ 'post.no_posts_found'|trans }}</div>
{% endfor %}
{% if paginator.hasToPaginate %}
<div class="navigation text-center">
<ul class="pagination pagination-lg">
{% if paginator.hasPreviousPage %}
<li class="page-item">
<a class="page-link" href="{{ path('blog_index_paginated', {page: paginator.previousPage, tag: tagName}) }}" rel="previous">
{{ component('ux:icon', { name: 'tabler:arrow-left' }) }} {{ 'paginator.previous'|trans }}
</a>
</li>
{% else %}
<li class="page-item disabled">
<span class="page-link">{{ component('ux:icon', { name: 'tabler:arrow-left' }) }} {{ 'paginator.previous'|trans }}</span>
</li>
{% endif %}
{% for i in 1..paginator.lastPage %}
{% if i == paginator.currentPage %}
<li class="page-item active">
<span class="page-link">{{ i }} <span class="sr-only">{{ 'paginator.current'|trans }}</span></span>
</li>
{% else %}
<li class="page-item"><a class="page-link" href="{{ path('blog_index_paginated', {page: i, tag: tagName}) }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if paginator.hasNextPage %}
<li class="page-item">
<a class="page-link" href="{{ path('blog_index_paginated', {page: paginator.nextPage, tag: tagName}) }}">
<span>{{ 'paginator.next'|trans }} {{ component('ux:icon', { name: 'tabler:arrow-right' }) }}</span>
</a>
</li>
{% else %}
<li class="page-item disabled">
<span class="page-link">{{ 'paginator.next'|trans }} {{ component('ux:icon', { name: 'tabler:arrow-right' }) }}</span>
</li>
{% endif %}
</ul>
</div>
{% endif %}
{% endblock %}
{% block sidebar %}
{{ parent() }}
{{ show_source_code(_self) }}
{{ include('blog/_rss.html.twig') }}
{% endblock %}