Remove Welcome to in Drupal 8 - drupal

How to remove "Welcome to" from header title on front page in Drupal 8
In drupal 7 you just add in page.tpl.php this part of code:
<?php if (!$is_front){
print render($page['content']);
} ?>

In D8 frontpage is a view. To change title of the front page, go to admin/structure/views/view/frontpage, find Global: Title override link
Open it and it will allow to set or remove custom front page title.

Default views with url /node we leave as it is.
In page.html.twig we output all blocks except content block:
{% if is_front %}
{{ page.content.breadcrumbs }}
{{ page.content.page_title }}
{{ page.content.local_tasks }}
{{ page.content.help }}
{{ page.content.local_actions }}
{#{{ page.content.content }}#} < no content
{% else %}
{{ page.content }}
{% endif %}
page-title.html.twig
{% if title %}
{# nothing #}
{% else %} {# for other pages #}
<h1{{ title_attributes.addClass('page-header') }}>{{ title }}</h1>
{% endif %}

Related

Drupal 8 newbie - How to access fields inside of page.html.twig?

{{ page.content.field_title.value }}
Is there anyway for me to access just the title field inside of my page.html.twig
To get the title, any of the following should work
{{ node.label }}
Or
{{ page[‘#title’]}}
But, I like the following
{% if node.title.value %}
<h1>{{ node.title.value }}</h1>
{% elseif page['#title'] %}
<h1>{{ page['#title'] }}</h1>
{% endif %}
From here

How to limit knp_paginator from extending?

I want to limit the pagination boxes going for ever. Say there is 100 events loaded -> 3 events are displayed/page; and such that the pagination boxes [1][2][3][4]....[40] doesn't go on...
In config.yml add this:
knp_paginator:
page_range: 5 # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6)
If you need change the sliding use any of these:
template:
pagination: '#KnpPaginator/Pagination/sliding.html.twig'
#KnpPaginator/Pagination/sliding.html.twig (by default)
#KnpPaginator/Pagination/twitter_bootstrap_v3_pagination.html.twig
#KnpPaginator/Pagination/twitter_bootstrap_pagination.html.twig
#KnpPaginator/Pagination/foundation_v5_pagination.html.twig
I guess that knp paginator does that for you but in case it does not You could try to modify any of the templates above to do something like this:
set a control variable
{% if pageCount > maxNumberOfBoxes %}
{% set breakpointAdded=true %}
{% endif %}
then find the loop which look like this
{% for page in pagesInRange %}
{% if page != current %}
<span class="page">
{{ page }}
</span>
{% else %}
<span class="current">{{ page }}</span>
{% endif %}
{% endfor %}
and replace it for something like this(with your own logic of course)
{% for i in range(0,pageCount) %}
{% if i > xBreakpoint and i < yBreakpoint and breakpointAdded == false %}
<span class="dots">...</span>
{% set breakpointAdded = true %}
{% else %}
{% if page != current %}
<span class="page">
{{ page }}
</span>
{% else %}
<span class="current">{{ page }}</span>
{% endif %}
{% endif %}
{% endfor %}
if anything of this works you could try to modify the getPaginationData function from SlidingPagination class.
what ever works for you.

SonataAdminBundle templates - list and show fields template content duplication

My list and show fields contain the same content, but due the extending of base_list_field and base_show_field templates I have to create two separate templates.
list/location.html.twig:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
{{ object.getCity }}, {{ object.getCountry.getName }}
{% endblock %}
show/location.html.twig:
{% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
{% block field %}
{{ object.getCity }}, {{ object.getCountry.getName }}
{% endblock %}
As you can see huge part of code is duplicated. Is there a way to check the page I am currently in in twig and then extend certain base template? In this case I would be able to use one file instead of two for same content.
In twig it's possible to extend/include a dynamic template :
{# do test here on which page you are or pass through controller #}
{% if true %}
{% set template = 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
{% else %}
{% set template = 'SonataAdminBundle:CRUD:base_list_field.html.twig' %
{% endif %}
{% extends template %}
{% block field %}
{{ object.getCity }}, {{ object.getCountry.getName }}
{% endblock %}
(edit) if you don't want the hardcoded if I would pass the template variable through the controller and change the twig template to something like
{% extends template|default('SonataAdminBundle:CRUD:base_show_field.html.twig') %}

Using Twig in Symfony 2: Translation inside an embeded block does not work

I am using Twig inside my Symfony 2 WebApp project. I use {% embed SomeTamplate %} to include the content of one template file in another. This workes fine, but translation is not working inside the embedded file.
Page Template:
{% extends 'AppBundle::layout.html.twig' %}
{% trans_default_domain mypages' %}
1: {{ 'pages.home.sometext'|trans }}
{% embed "block.html.twig" with {'classes': 'homepage-hero'} %}
{% block content %}
2: {{ 'pages.home.sometext'|trans }}
{% endblock %}
{% endembed %}
{% embed "block.html.twig" with {'classes': 'red-bg'} %}
{% block content %}
3: {{ 'pages.home.sometext'|trans }}
{% endblock %}
{% endembed %}
Block template:
{% trans_default_domain mypages' %}
<div class="full-width-block{% if classes is defined %} {{ classes }}{% endif %}">
X: {{ 'pages.home.sometext'|trans }}
{% block content %}
{% endblock %}
</div>
Output:
1: SomeText
X: SomeText
2: pages.home.sometext
X: SomeText
3: pages.home.sometext
So: While the translation works fine within the two template files, the same text constant within the embedded block, is not translated. How can I fix this?
the domain must be enclosed in quotes, just put the last quotation mark.
Visit http://symfony.com/doc/current/book/translation.html
Put it this way:
{% trans_default_domain "mypages" %}
I hope your problem is solved

Twig use function multiple parameter

I am looking for using function "{% use %}" with multiple parameter in twig template.
all page template
{% use "common.html.twig" with
container as containerParent,
title as titleParent
%}
{# Some code ... #}
common.html.twig
{% block title %}{{ block(titleParent) }} - Admin{% endblock %}
{% block container %}
{# Some code ... #}
{{ block(containerParent) }}
{# Some code ... #}
{% endblock %}
When I tried that, my block container and title are not modified.
Maybe I didn't understood the doc ? http://twig.sensiolabs.org/doc/tags/use.html
I just want have access to function twig {{ parent() }} in my twig file which is included by {% use ... %}
Any suggestion ?
Sorry for my English, I am learning it...

Resources