I'm very new to symfony2 and twig templating in general.
My question is related to the FOSUserBundle.
I have a base template which has 2 columns, {% block left %} and {% block right %}
I have created a new file: Base5/UserBundle/Resources/views/layout.html.twig
which extends my 2 column layout
{% extends '::base_2col.html.twig' %}
{% block left %}
I want this text to change depending on wether a login form, register form, profile page etc is displayed
{% endblock %}
{% block right %}
{{ block('fos_user_content') }}
{% endblock %}
as the actual form is rendered using {{ block('fos_user_content') }}, how can i change the text in the right panel depending on what form is displayed, ideally i want to use a different include, containing the various descriptions into texts for the diffirent form.
Any pointers would be very much appreciated.
Found out, just a question of duplicating the templates from the fosuserbundle views directory
Related
I extend FosUserBundle register form like this:
{% extends "#App/base.html.twig" %}
{% form_theme form 'bootstrap_3_horizontal_layout.html.twig' %}
{% block form_label_class -%}
col-md-8
{%- endblock form_label_class %}
Unfortunately the block form_label_class which is from bootstrap_3_horizontal_layout.html.twig is not extending there.
I want now in my form to use label as col-md-8 (instead the default col-sm-2) but then in another form maybe want to use col-md-6 and so on.
Is there an easy way to do it inline in every from instead create extends for each col-md-XX which is really not very convenient at all.
Thanks a lot!
You need to tell Symfony to include your current template as a form theme:
{% form_theme form with [
'bootstrap_3_horizontal_layout.html.twig',
_self,
] %}
Otherwise, it doesn't know to look in the current template for form theme blocks.
You can also use this to include other templates with form blocks as well. This is helpful if you have multiple templates that re-use the same form blocks; you can refactor them all into one template and reference it everywhere it's needed.
I'm trying to use Drupal 8, with an own theme, due big structure differences for my requirements I have a page--front.twig.html and a page.twig.html, I would like to create template parts as used in phrozn oder in a normal Symfony2 project, for example a footer.html.twig and a header.html.twig. These templates are saved under a subdirectory /parts/
But wenn I call this templates as normal I just receive a string with the name of the template.
For example:
{# in page.html.twig or page--front.html.twig #}
{% include 'parts/footer.html.twig' %}
Returns the file name as string:
parts/footer.html.twig
It's possible to do that with Drupal 8?
You can include any part of your template files like this
{% include directory ~ '/parts/footer.html.twig' %}
or this
{% include '#mytheme/parts/footer.html.twig' %}
I strongly recommend you to create a reusable layout for pages that will give you greater flexibility when dealing with more pages and variants.
{# filename: page-layout.html.twig #}
{% block content%}
{{ page.content }}
{% endblock%}
{% block footer%}
{% include '#mytheme/parts/footer.html.twig' %}
{% endblock%}
So you can do something like this in another page
{# filename: page--front.html.twig #}
{% block footer%}
<div> I want to handle a different footer in here</div>
{% endblock%}
Finally, I found really helpful to dig into suggestions array and see what Drupal is trying to use.
Cheers.
it's possible using the name of the template in the path
{% include '#mytheme/parts/footer.html.twig' %}
thanks to https://drupal.stackexchange.com/questions/141066/drupal-8-include-part-template
Now that https://www.drupal.org/node/2291449 has been committed you can also do:
{% include 'footer.html.twig' %}
I have created the custom data collector for profiler as described here http://symfony.com/doc/current/cookbook/profiler/data_collector.html .
Now everything is working correctly except of {% block panel %} in template which defines the content area for my information. I have everything in place but on the screen tha page is almost without styles so its visualy broken.
When I compare my panel page and some other from profiler the mine lacks of cca. 200 lines of styles that Symfony is adding to the page header to style the page. I miss style for #content as an example. I tried to clear cache and refreshed everything but still now way. Any idea what is going to be wrong here?
This is waht I see in the browser ...
EDITED: Template
{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %}
{% block toolbar %}
{% endblock %}
{% block head %}
{% endblock %}
{% block menu %}
<span class="label">
<strong>NET.Notes</strong>
</span>
{% endblock %}
{% block panel %}
panel david
{% endblock %}
It is due to empty block of "head". Rust remove it or include parent block by {{parent()}}.
{% block head %}
{#if the web profiler panel needs some specific JS or CSS files #}
{% endblock %}
I know that i can override checkbox_widget in my form_theme file like that
{% block checkbox_widget %}
my Code
{% endblock checkbox_widget %}
The problem is that I have all files loaded globally so in this way I would override all checkbox_widget in application. But i need to override checkbox in one form.
So the question is How i can override checkbox_widget for one specific form or override specific field widget somehow ?
I tried something like this but it doesn't works:
{% block MyFormName_checkbox_widget %}
my Code
{% endblock MyFormName_checkbox_widget %}
You have to use twig macros instead of blocks. Docs here: macro and import.
I have two django templates in my one folder. The template for the url localhost:8000/people picks CSS correctly which is located at /m/css/style.css
The other template for the url localhost:8000/people/some-name in the same folder is trying to retrieve CSS from people/m/css/style.css
Why is this second template not picking CSS like the first one?
My erring second template is like this:
{% extends "base.html" %}
{% block page_title %}{{ entry.name }} | {{ block.super }}{% endblock %}
{% block main %}
<h1>{{ entry.name }}</h1>
{{ entry.body|linebreaks }}
{% endblock main %}
As you can see there's nothing in the template that could cause problem.
It looks to me like your templates are looking for a stylesheet located at ../m/css/style.css. That's why the template in /people works - /people/../m/css/style.css refers to /m/css/style.css. However, /people/some-name/../m/css/style.cssrefers topeople/m/css/style.css`, not the desired address.
Make sure the templates are looking for /m/css/style.css - emphasis on the very first / character.