Questions tagged [twig]
Twig is a modern, fast, flexible, and secure templating engine for PHP. Created for Symfony and adopted by Drupal 8.
10,609
questions
2
votes
1
answer
19
views
Shopware 6 override pagination.html.twig not working
I'm trying to override the pagination.html.twig template in my Shopware 6 storefront but it's not working.
My pagination.html.twig is:
{% sw_extends '@Storefront/storefront/component/pagination.html....
0
votes
0
answers
9
views
How in Drupal to get a link from a field (Media->Document) in Paragraph?
I have a Drupal paragraph with 3 fields:
The "File" field is a "Media" field with type "Document"
I'm trying to display values of these fields in .twig file of this ...
0
votes
0
answers
29
views
how to set style in javascript to a url link when this page load
I have a admin panel and agent panel,I want to hide the sidebar in agent panel first then i used this code
{% block body_header %}
{% if data.username == 'client' %}
{% include 'block/menu....
0
votes
1
answer
32
views
Why does this ACF field not update properly?
I'm using Timber and Twig for a Wordpress site that I'm currently working on, but got stuck in this (for me) quite weird behaviour of an ACF field.
The ACF field is a simple true/false checkbox and in ...
-2
votes
0
answers
29
views
Twig Checkbox Check If Already Checked Via MYSQL
<input type="checkbox" class="form-control form-check-input me-2 " name="user[two_fa]">
So i have this input checkbox so users can select if they enable 2fa on ...
1
vote
1
answer
34
views
Symfony 6 form trouble
Currently working on a new web project running under Symfony 6. Unfortunately, I just caught this error :
Variable "ajouterNouveauProjet" does not exist.
By the way, I cannot find the issue !...
-1
votes
1
answer
44
views
Twig print values and strings in set statements
This twig template is not DRY.
{% set reviewer_0 = webform_token('[webform_submission:values:reviewer:0:entity:mail:clear]', webform_submission, [], options) %}
{% set reviewer_1 = webform_token('[...
-1
votes
1
answer
49
views
How to add two letter gb flag to all english languages in symfony 6?
I set up the translation with symfony 6 and the intl package (also intl-extra), everything works perfectly, now I'd like to add the ability to switch language, so I've added this to my twig template:
&...
1
vote
0
answers
40
views
using "global" variables by loading into a file - twig
Hi, I have a problem with loading variables from a separate file.
I have a set of components that have the same variables - I pulled them into a separate file to complete them in one file.
The ...
-3
votes
0
answers
35
views
Im trying to get html snippets onto my twig file (index.html.twig)
i did try changing the settings.json file on my vs code and tried reloading page switched off my laptop as well but didnt really work for reference im watching this video on symfony https://www....
0
votes
1
answer
32
views
How to override `storefront/component/line-item/element/label.html.twig` on cart page?
Would like to override storefront/component/line-item/element/label.html.twig file available on the cart page.
I tried to add the below code in the override twig template then it is throwing an error ...
0
votes
0
answers
34
views
Problem with Eszett while using Twig raw filter
The following string contains html-tags:
<span>Schweißer</span>
For that reason i output that string as follows:
{{ myVariable | raw }}
I get the output "Schweisser" instead of ...
0
votes
0
answers
25
views
Shopware 6.5.4.0 snippet name shows when empty [duplicate]
I would like to use a snippet to determine the content of an element and if the snippet is empty, the element should not be displayed.
But if the snippet is empty its own name is always displayed as a ...
-2
votes
0
answers
44
views
Twig/Symfony isGranted method returning always true
I have a problem with the isGranted method, it every time returns only "true", even if I tried this:
{{ dump(is_granted('blablabla')) }}
{{ dump(is_granted('whwhwhwhwhwhwh')) }}
But every ...
0
votes
0
answers
14
views
How to print layout builder sections inside of a twig file in Drupal 8
I am looking to set up a three column grid in Layout Builder to be printed within a bootstrap col-md-4 div. I am wondering how I can print each column within its own bootstrap column.
My main thing is ...
0
votes
0
answers
31
views
WordPress Timber/Twig: Failed to load Twig template, cache might be corrupted fatal error when upgrading to PHP 7.4.x
I maintain a website on WordPress coded with Timber/Twig and ACF Blocks. Local installation runs on a Windows/Laragon with PHP 8 and is okay. Staging installation runs on a shared hosting A with PHP 7....
0
votes
2
answers
70
views
how to solve Twig environment not injecting into shopware 6.5.4.0 when trying to use twig function
I am working on a custom plugin that accepts data from an api.
I am trying to use a twig function to get the data as below
twig function class:
<?php declare(strict_types=1);
namespace Nst\Twig;
...
0
votes
0
answers
24
views
Rendering issue for Symfony forms ChoiceType for a new entity in a CollectionType
In my web application I can create/edit/delete shifts in a shift schedule. These shifts are loaded as a table.
Now the problem is when creating a new shift (existing shifts don't have this issue) in ...
0
votes
0
answers
15
views
Problem in getting the selected value from a form in symfony
I'm new to symfony and i want to get a selected value from twig template to the controller :
my code is as shown below :
index.html.twig
{{ form_start(formSave) }}
{{ form_widget(formSave.nomRecherche)...
0
votes
1
answer
28
views
Filling a select2 with given send to javascript
On an application I created a form with a field (select) in EntityType, I then passed it to select2, no problem there.
The twig view looks like an array of all saved helpers and you can modify a ...
-2
votes
1
answer
47
views
How to have an image display in a twig template and act as a link for Drupal?
I have the following code on my website in a .twig file
<a href="https://appointments.detailandsupply.com/easyappointments/index.php?service=14" style="color: lightgreen; font-weight:...
0
votes
1
answer
96
views
Shopware 6: sw-inherit-wrapper for sw-snippet-field and sw-media-field component in Vue.js
I am in the process of programming a custom administration module (plugin configuration) in Shopware 6 using Vue.js.
The problem I have encountered is the lack of sw inherit wrapper that shows up when ...
0
votes
0
answers
14
views
Drupal 9, Url segment conditionals in Twig
Url: example.com/urlsegment1/urlsegment2
How do you achieve the same as the below PHP code with Twig in Drupal 9. I specifically need the code to work within paragraph.html.twig templates. I want to ...
0
votes
2
answers
74
views
Check (in twig template), if Shopware 6 customer belongs to a specific customer group
I know this Shopware 6 twig condition:
{% if context.customer is defined %}
do show
{% endif %}
But how to check, if a customer belongs to a specific customer group?
0
votes
0
answers
25
views
Symfony twig namespaces for bundles
does anyone know how I can add twig paths (the path where Symfony looks for templates) dynamically for bundles?
I found that in the documentation: https://symfony.com/doc/current/templates.html#...
0
votes
1
answer
69
views
opencart | Print array of objects in twig file
I'm using opencart. There I'm sending array of objects to twig file from controller.
Controller
$data['crackers'] = [];
$results = $this->model_quickorder_order->getCrackers();
$...
0
votes
2
answers
170
views
Drupal 9 - Output Views "Content: Link to Content" url to views-view-unformatted....html.twig template
I am trying to output the url alias from Views "Content: Link to Content" in a Twig template of the format views-view-unformatted....html.twig. The url alias outputs successfully in the ...
1
vote
1
answer
41
views
Remove duplicate data from the Twig object and combine it
In my Twig template i have list, something like this:
1985 - John
1974 - Lena
1985 - Sandra
1974 - Tom
1985 - Jess
The year can be duplicated. So i need combine my list like this:
1985 - John, Sandra,...
0
votes
0
answers
35
views
Render twig template
I am trying to use Twig in my native php application for rendering templates. And i have some problems with it.
I have next View class
class View
{
protected Environment $twig;
public ...
0
votes
1
answer
61
views
Shopware 6 Plugin: Issue with Generating SEO-Friendly URLs in Pagination for Search Results
I'm facing an issue with generating SEO-friendly URLs in Shopware 6 when implementing pagination for search results. I have a custom Twig template that extends the pagination.html.twig template from ...
1
vote
1
answer
41
views
How to render twig content from database (overwrite render function)?
For several reasons i stored some twig templates in my database (twig path + html markup).
I want to achieve the following:
When i call the render function in my controller (extends Controller), i ...
0
votes
0
answers
15
views
Inconsistent ability to adjust blocks using Twig due to naming conventions (underscores, etc)
I am having difficulties getting my Drupal blocks and regions to interact with my Twig Template Files. I suspect some of it may be syntax but a lot of it seems to be understanding what to name my Twig ...
0
votes
0
answers
33
views
Embedding Controllers in Twig including dependency injection in parameter
I am using Symfony 6.3 with Twig. I have a nav partial templates in which I would like to send some datas from a Repository Class. I saw in the Symfony documentation that embedding a Controller in a ...
1
vote
2
answers
81
views
Get a string from a text field using twig and craft CMS
I am using twig and craft CMS.
How can I access just one word from a text field and underline it?
As an example of what I want the result to be, I have provided a HTML and CSS code.
<p>
...
0
votes
0
answers
24
views
How can I sort a name with a comma in Twig in alphabetical order? Ex: John Doe, CFP
I'm trying to sort alphabetically by either first or last name using Twig Sort with a name that has a comma in it.
Example
John Doe, CFP
Jane Doe, MBA
I want to sort this alphabetically such that ...
1
vote
0
answers
81
views
Twig infinite loop when rendering templates that have a Symfony Form in them. (Symfony 5.4)
I am trying to upgrade a legacy PHP application from PHP 7.2 and Symfony 3.4 to currently supported versions (8.2 / 5.4 respectively), and am running into an infinite loop when rendering certain twig ...
0
votes
0
answers
26
views
Twig form/input without symfony
is there a way to pass the form/input value from twig file to controller without using symfony?
Tried using getQueryParams but it only work if you put a value in the url.
1
vote
2
answers
145
views
How to clear Twig cache fragments from Symfony?
I'm using the twig cache in a Symfony 5.4 project. If I cache something like:
{% cache "customer_1" ttl(3600) tags('customer') %}
Some HTML here
{% endcache %}
I need to be able to ...
0
votes
2
answers
46
views
How to determine if last character is a dot and, if so, remove it
I have a webform with an open text-field in which anything can be entered. I need to display that input verbatim in a sentence, as part of a block of text.
What I want to do is to check if the last ...
1
vote
0
answers
50
views
how to use a form in each template?
I have a search bar in my navbar and and for the management of the search bar, I don't want to manage it in the controllers of each route.
Here is my SearchForm :
class SearchForm extends AbstractType
...
0
votes
1
answer
31
views
Symfony 6 form_widget translations
I've been strugling with setting translation for form's labels in a project in Symfony 6 lately.
I've got ExampleController which passes $form = $this->createForm(ExampleType::class, $example) to ...
1
vote
1
answer
27
views
Custom Tag appears in the result selection list, but it doesn't show up in the form field after reopening the modal
Custom Tag Id for Property Options saved into database and Tag appears in the result selection list. But it doesn't show up in the form field after reopening the (Option details) modal:
<sw-entity-...
0
votes
0
answers
55
views
How to update symfony context in twig after ajax call
I'm doing a search by filter as you can search an article on an e-commerce by applying some filters.
For the page load:
In the controller I render the twig template with the context that contains the ...
0
votes
0
answers
61
views
Extract and truncate plain text from HTML content using Twig in Winter CMS
I'm working on a blog template in Winter CMS using Twig as the templating language. Within my template, I have a field called post.summary that contains HTML content, including a video embed code.
For ...
0
votes
0
answers
93
views
Shopware 6: How to place the filter on top instead of the sidebar?
How to place the filter to be adjacent to the sorting in the storefront?
From the layout editor, I moved the sidebar-filter on top of the listing, but it is not aligned with the sorting as I want to ...
0
votes
0
answers
30
views
Set a twig variable from an external JS file
I want to set the value of my twig variable from an external js file.
I have this code in twig:
{% set items = null }
{% include "list.twig" with { itemList: items} %}
And I want to set the ...
0
votes
1
answer
93
views
Compile Tailwind classes based on Twig variable
Let's say I've set a variable in Twig based based on a condition. Now I want to use the output of the variable as class like this:
{% set color = test ? 'text-black' : 'text-white' %}
<div class=&...
1
vote
1
answer
43
views
In Symfony 6 how to create a global variable which is coming from the database?
Currently i'm trying to create a variable which holdes a value that coming from the database which i need pretty much in all the views and controllers.
Please help, I tried different solution like ...
0
votes
0
answers
65
views
KISS with {include} or fancy code with {extends}
I'm a backend (PHP) developer, but I have converted some (static) HTMLs to dynamic templates (for different people, with different levels of coding knowledge).
It doesn't matter which template engine ...
1
vote
1
answer
52
views
Shopware 6 Twig - HTML Entity decode
I try to decode html entities like & which are inside the products description and should be decoded for Feedexport.
As the entities are already inside of the description the |raw filter will ...