I'm overriding Skeleton templates of SensioGeneratorBundle as describred in:
http://symfony.com/doc/current/bundles/SensioGeneratorBundle/index.html#overriding-skeleton-templates
So until here is everything fine.
In one of the templates of SensioGeneratorBundle I have:
# app/resources/SensioGeneratorBundle/skeleton/crud/views/new.html.twig.twig
{% block body %}
{{ "{% block page_title 'Incluir " ~ entity ~ "'%}" }}
{{ "{% block body -%}" }}
{{ '{{ form(form) }}' }}
{% set hide_edit, hide_delete = true, true %}
{% include 'crud/views/others/record_actions.html.twig.twig' %}
{{ "{% endblock %}" }}
{% endblock body %}
This works, but {{ form(form) }} is rendering the submit button, and I want to render the submit button in the record_actions.html.twig.twig.
So my question is: How to render a form without render the submit button? Remembering that i'm trying to do this in the skeleton template, in this moment I don't have the fiels of the form to iterate over it.
Thanks!
The solution for this problem is as follows:
# app/resources/SensioGeneratorBundle/skeleton/crud/views/new.html.twig
{% block body %}
{{ "{% block page_title 'Incluir " ~ entity ~ "'%}" }}
{{ "{% block body -%}" }}
{{ " {{ form_start(child) }}" }}
{{ " {% for child in form %}" }}
{{ " {% if child.vars.name != 'submit' %}" }}
{{ " {{ form_row(child) }}" }}
{{ " {% endif %}" }}
{{ " {% endfor %}" }}
{% set hide_edit, hide_delete = true, true %}
{% include 'crud/views/others/record_actions.html.twig.twig' %}
{{ "{% endblock %}" }}
{% endblock body %}
And inside record_actions.html.twig.twig
# app/resources/SensioGeneratorBundle/skeleton/crud/views/record_actions.html.twig
{{ " {{ form_row(form.submit) }}" }}
{{ " {{ form_end(form) }}" }}
<ul class="record_actions">
<li>
<a href="{{ "{{ path('" ~ route_name_prefix ~ "') }}" }}">
Back to the list
</a>
</li>
{% if ('edit' in actions) and (not hide_edit) %}
<li>
<a href="{{ "{{ path('" ~ route_name_prefix ~ "_edit', { 'id': entity.id }) }}" }}">
Edit
</a>
</li>
{% endif %}
{% if ('delete' in actions) and (not hide_delete) %}
<li>
<form action="{{ "{{ path('" ~ route_name_prefix ~ "_delete', { 'id': entity.id }) }}" }}" method="post">
<input type="hidden" name="_method" value="DELETE" />
{{ '{{ form_widget(delete_form) }}' }}
<button type="submit">Delete</button>
</form>
</li>
{% endif %}
</ul>
Related
Trying to do "if homepage hide " a button.
Current code is here...
<div class="mobile-bar sticky-bar">
{% if j3.settings.get('mobileCustomMenuStatus1') %}
<a class="mobile-custom-menu mobile-custom-menu-1" href="{{ j3.settings.get('mobileCustomMenuLink1.href') }}" {{ j3.linkAttrs(j3.settings.get('mobileCustomMenuLink1.attrs')) }} style="margin-left:10px; margin-right:-30px">
{{ j3.countBadge(j3.settings.get('mobileCustomMenuLink1.name'), j3.cache.update(j3.settings.get('mobileCustomMenuLink1.total')), j3.settings.get('mobileCustomMenuLink1.classes')) }}
</a>
{% endif %}
{% if j3.settings.get('mobileCustomMenuStatus2') %}
<a class="mobile-custom-menu mobile-custom-menu-2" href="{{ j3.settings.get('mobileCustomMenuLink2.href') }}" {{ j3.linkAttrs(j3.settings.get('mobileCustomMenuLink2.attrs')) }}>
{{ j3.countBadge(j3.settings.get('mobileCustomMenuLink2.name'), j3.cache.update(j3.settings.get('mobileCustomMenuLink2.total')), j3.settings.get('mobileCustomMenuLink2.classes')) }}
</a>
{% endif %}
You can store the current page within a $data variable in your menu controller just like this:
$data['current_url'] = $_SERVER['REQUEST_URI'];
Within your twig file you can check it's value against whatever you want. This can be achived using a small vqmod or ocextension.
I am new to this platform and the syntax. We have custom social media icons in our theme. Example:
<a href="{{ module.link_sharetw }}" class="share-button twitter">
<img src="{{ get_asset_url('/greenpeace_p4_theme/assets/twitter.svg') }}" />
</a>
I would like to replace the default icons used in the social sharing module here. Is it possible?
{% set size = "24px" %}
{% set borderRadius = "3px" %}
{% set linkStyle = "width:"~size~";border-width:0px;border:0px;text-decoration:none;" %}
{% set imgStyle = "height:"~size~";width:"~size~";border-radius:"~borderRadius~";border-width:0px;border:0px;" %}
{% macro render_social_icon(networkName) %}
{% set network = module[networkName] %}
{% if (networkName == "pinterest" and network.pinterest_media and network.enabled) or (networkName != "pinterest" and network.enabled) %}
{% if networkName == "pinterest" %}
{% set pinterest_media = module.pinterest.pinterest_media.src %}
{% endif %}
{% set logo = networkName ~'-color.png' %}
{% set urlOperator = "&" if "?" in page_meta.canonical_url else "&" %}
{% if module.link %}
{% set social_link_url = module.link ~ urlOperator ~ "utm_medium=social&utm_source="|safe ~ networkName %}
{% elif content.email_type.blogRssChild %}
{% set social_link_url = content.rss_email_url %}
{% else %}
{% set social_link_url = page_meta.canonical_url ~ urlOperator ~ "utm_medium=social&utm_source="|safe ~ networkName %}
{% endif %}
<a href="{{ network.custom_link_format }}" target="_blank" rel="noopener" style="{{ linkStyle }}" >
<img src="{{ module_asset_url(logo) }}" class="hs-image-widget hs-image-social-sharing-24" style="{{ imgStyle }}" width="{{ size }}" hspace="0" alt='{{ "Share on " ~ networkName }}' />
</a>
{% endif %}
{% endmacro %}
<div class="hs_cos_wrapper hs_cos_wrapper_widget hs_cos_wrapper_type_social_sharing" data-hs-cos-general-type="widget" data-hs-cos-type="social_sharing">
{{ render_social_icon('facebook') }}
{{ render_social_icon('linkedin') }}
{{ render_social_icon('share_twitter') }}
{{ render_social_icon('pinterest') }}
{{ render_social_icon('email') }}
</div>
I know there is a way to replace social media icons in the module inspector but it only takes pngs.
On line 12 you have a
{% set logo = networkName ~'-color.png' %}
which is defining the name expected for the icon. Change .png to .svg and it should render just fine.
Apologies if this has been asked before, but I'm on my first week working with Drupal and Twig.
I have the following code:
{%
set container_classes = [
'paragraph',
'paragraph--type--' ~ paragraph.bundle|clean_class,
view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
not paragraph.isPublished() ? 'paragraph--unpublished',
'container'
]
%}
{% set image_classes = [
'col-12'
]
%}
{% block paragraph %}
{% block content %}
<div{{ attributes.addClass(container_classes) }}>
<div class='row'>
<div{{ attributes.addClass(image_classes) }} data-type='image'>
{{ content.field_two_column_image }}
</div>
<div class='col-12 col-lg-auto' data-type='copy'>
{{ content.field_two_column_copy }}
</div>
</div?>
</div>
{% endblock %}
{% endblock paragraph %}
My issue is the nested attributes.addClass. When I look at the HTML, I'm also seeing the container_classes classes, which is not what I'm looking for.
So how can I separate the two?
You can Create Attributes in Twig.
Something like this should work.
{# attributes for container #}
{% set container_attributes = create_attribute() %}
{%
set container_classes = [
'paragraph',
'paragraph--type--' ~ paragraph.bundle|clean_class,
view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
not paragraph.isPublished() ? 'paragraph--unpublished',
'container'
]
%}
{% set container_attributes = container_attributes.addClass(container_classes) %}
{# attributes for image #}
{% set image_attributes = create_attribute() %}
{% set image_classes = [
'col-12'
]
%}
{% set image_attributes = image_attributes.addClass(image_classes) %}
{% block paragraph %}
{% block content %}
<div{{ container_attributes }}>
<div class='row'>
<div{{ image_attributes }} data-type='image'>
{{ content.field_two_column_image }}
</div>
<div class='col-12 col-lg-auto' data-type='copy'>
{{ content.field_two_column_copy }}
</div>
</div?>
</div>
{% endblock %}
{% endblock paragraph %}
I am creating a form using python/flask, but getting the error that I posted in the title. I am not able to figure out where the problem is. Can you please help!
{% extends "base.html %}
{% block content %}
<h1>Sign In</h1>
<form action="" method="post">
{{ form.hidden_tag() }}
<p>
{{ form.username.label }}<br>
{{ form.username(size=32) }}
</p>
<p>
{{ form.password.label }}<br>
{{ form.password(size=32) }}
</p>
<p>{{ form.remember_me() }} {{ form.remember_me.label }}</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}
{% extends "base.html %}
Missing ":
{% extends "base.html" %}
How can I output this HTML block with a nested TWIG counter variable {{ i }} like: eco-item-2.jpg, eco-item-3.jpg and eco.benefits.item.header.2, eco.benefits.item.header.3 and so on…?
{% for i in 0..3 %}
<section class="eco-benefits">
<img src="{{ asset ('img/eco-item-1.jpg') }}" class="th">
<dl>
<dt>
{% trans from 'eco' %}
eco.benefits.item.header.1
{% endtrans %}
</dt>
<dd>
{% trans from 'eco' %}
eco.benefits.item.text.1
{% endtrans %}
</dd>
</dl>
</section>
{% endfor %}
You can concatenate strings using the ~ operator:
{% for i in 0..3 %}
<section class="eco-benefits">
<img src="{{ asset ('img/eco-item-' ~ (i + 1) ~ '.jpg') }}" class="th">
<dl>
<dt>{{ ('eco.benefits.item.header.' ~ (i + 1))|trans(domain = 'eco') }}</dt>
<dd>{{ ('eco.benefits.item.text.' ~ (i + 1))|trans(domain = 'eco') }}</dd>
</dl>
</section>
{% endfor %}