Questions tagged [twig]
Twig is a modern, fast, flexible, and secure templating engine for PHP. Created for Symfony and adopted by Drupal 8.
10,321
questions
0
votes
0
answers
5
views
Drupal 9 Views Templates Twig Programmatically Add Field Values Together to get Average from Total
OK, I have a fivestar field used for rating on a content type called customer reviews - machine name of field: field_rating, machine name content type: customer_review.
I am trying to add all the ...
0
votes
0
answers
16
views
"evaluate" filter in Twig
I found a this evaluate filter used in one of the projects in my company. Symfony and Twig are used for the projects.
<a href="{{ bulletUrl | evaluate }}" class="list-group-item text-...
0
votes
0
answers
14
views
Is there a way to define logic in a block rather than in a bunch of individual tags?
For Example I have quite a lot of logic that looks like this
{% set allowed_observations = ["PAR;101;ZN_GYM", "PAR;101;ZN_CARDIOGYM", "PAR;101;0;G15"] %}
...
-2
votes
0
answers
19
views
make:registration-form resulting in a blank page? [duplicate]
I made a registration page using php bin/make:registration-form and the default arguments/parameters, it worked but when I visit https://127.0.0.1:8000/register there is just a blank page, view source ...
-1
votes
0
answers
16
views
Symfony Twig timer dynamic
for a little game project in Symfony I want to add a dynamic timer on my page.
For the context the user will be able to click on a button, this button will trigger the timer (for example a timer of ...
-1
votes
0
answers
36
views
Best practise to extend symfony TemplateController in order to add global variables
i would like to extend TemplateController in order to use some global variables.
At this moment I wrote all variables in twig.yaml, but I want to change it easily through admin panel.
Service is not ...
0
votes
1
answer
32
views
Symfony render controller
want to display a form in a modal in the header. In order to make the form work I call the controller Homecontroller.
I called the controller with render controller in the branch but I got a blank ...
0
votes
0
answers
24
views
Print the table based on the selected option of a radio element
I have a radio element with three options (Normal, Time Sensitive, and Hold For Pick-Up). Every time an user clicks an option, an unique table element for the option (for user to fill information) ...
0
votes
0
answers
25
views
How to Iterate array with special characters
$referral_leaderboard = $db->query("SELECT referrer, COUNT(*) FROM users WHERE NOT referrer = '' GROUP BY referrer ORDER BY COUNT(*) DESC")->fetchAll();
Here is the value of my array ...
0
votes
0
answers
16
views
printing the text of the select element from composite instead of key
I am trying to iterate and print the text of the select element selected by the user. The key of the composite is item.
{% for item in data.item %}
<tr>
<td style="text-align:...
1
vote
4
answers
55
views
reuse content of part of url in html
i would like to reuse parts of the url in the content of the webpage
as example
domain.com/specialist/brand/location/
where i want to reuse "brand" multiple times in the content of the ...
0
votes
1
answer
20
views
The listing is incorrect
can anyone please help me with this formula? It doesn't give me what I need. The first two posts to the active section, all the others to the inactive one.
{% set memberLength = members|length / 2 ...
0
votes
0
answers
21
views
How to render Twig templates within React?
I am creating a web application that basically consists of the user being able to display some kind of information with a template of his choice. The application will provide him with a couple of ...
0
votes
0
answers
17
views
Display dynamic content
I'm currently struggling to figure out how to display the name of a campaign dynamically using Twig. I know how to display a list of the campaign names using the following code:
{% for campaign in ...
-1
votes
1
answer
38
views
How to add my html javascript popup to my php function? [duplicate]
I want to add my javascript popup code which is in an html file to my php function.
It's a visitor counter in php. I want when visitors visit the page 4 times my popup html js is displayed
0
votes
1
answer
35
views
Shopware6 : Admin module not updatable
The default functionnality of Shopware does not shows the company name when we use the search bar in the admin panel. We have some customers only filling the company field and not using the first and ...
0
votes
1
answer
19
views
Set a new value depending on what the original value is?
In Drupal views, I have a twig variable available to me called {{ name }}. This stores a list of taxonomy terms depending on the type of content used. I currently have a function running something ...
1
vote
0
answers
45
views
Dynamically set timezone in twig
At the moment we take the dates from database which is in UTC and directly print it in the view.
Like
{{ createdAt | date("m/d/Y") }}
Now we need to display some dates in twig in users ...
1
vote
2
answers
57
views
using random function but it's displaying duplicates
I am using the random function in twig and it is randomizing the images I need but it is repeating the logos. How can I make it so that the images are not repeated but are still randomized?
this is my ...
0
votes
0
answers
19
views
Should I use site.link or site.url in Twig/Wordpress? [duplicate]
Should I be using {{ site.link }} or {{ site.url }} in Twig/WordPress for my theme development? They both seem to do the same thing and wanted to make sure I was correct and consistent.
Thanks so any ...
-1
votes
0
answers
23
views
How to Include an Angular2 component inside a PHP application(TWIG templates)
On my project, some of the websites are made in PHP, and some are in Angular2+ (different subprojects). my task is to check whether it is possible to insert an angular component in the middle of the ...
-1
votes
0
answers
28
views
Dynamically add more checkboxes based on amount of records
Hello guys I would like to ask help on creating something like a checklist.
I want to create a dynamic checklist, in my case each checklist has an undefined amount of checkboxes that can be ticked.
...
0
votes
2
answers
69
views
How to merge duplicates
I want to merge the same records to:
Audi A3 / S3 / RS3
8V / 8Y
Audi A4 / S4 / RS4
B8 / B9
etc.
But now it looks like that
Here is my repository code:
public function cars(): array
{
$conn =...
0
votes
0
answers
28
views
How to show a logo on every page of multi page pdf in template
I am using snappy bundle to generate a pdf from the twig file (Symfony 3.4). The number of pages increases as the content increases. Here, now I am wanted to add the company logo on top of every page. ...
0
votes
0
answers
29
views
Sylius: How to extend product admin interface with grid of custom model
I extended the product model to include an extra list of key-value pairs per product.
Like this:
product A : extraEnt1 => floatvalue1, extraEnt2 => floatvalue2
product B : extraEnt1 => ...
0
votes
1
answer
18
views
Print variable inside function 'wp_editor'
I am trying to define initial value for Wordpress textarea with twig.
So I use this code:
{% set job_text = "test text" %}
{{ fn('wp_editor', "{{ job_text }}", 'post_content', {'...
0
votes
0
answers
41
views
How to send data from a controller to a view (twig) on each iteration of a loop in symfony
I want to send a value from a controller to a view on each iteration of a foreach loop.
Context:
I have an array that has 100 elements as an example. In the controller, I want to loop the array and ...
0
votes
0
answers
49
views
Get image width and height in twig
I have an image like so:
<img alt="{{ title }}" src="{{ asset('build/images/image.png') }}" />
now I would like to get the image width and height and add width and height ...
0
votes
1
answer
40
views
How to get value from checkbox list in October CMS custom plugin
I entered project_toolbox into my plugin's database table and created checkbox list named project_toolbox with 10 values. How can I retrieve those value if checked from the backend.
Here is what I was ...
0
votes
0
answers
26
views
Value rendered by Controller not getting displayed
So I'm working with Symfony 4.4 and I'm facing an issue here.
I have the following script responsible for getting the value of an input tag and sending it back as json to the controller
{% if ...
0
votes
2
answers
29
views
How to use gettext with Twig templates in Slim Framework?
I'm working with Slim 4 Framework with a Twig engine for templates.
Some time ago, Twig had an extension with {% trans %} tokens and |trans filter directly linked to gettext function.
Now things seems ...
1
vote
1
answer
35
views
Pass Associative Array from Symfony Controller to Twig and JavaScript
So, I have 2 arrays that I've combined into one array after making sure they're the same length as such.
//Fetching Ratings for All Coaches & Making a Key, Value Associative Array with Coach id as ...
0
votes
0
answers
27
views
How can I assign a JS function to a list of tag that are generate with a loop?
I have a loop in my twig file :
{% for item in listItem %}
<h2 class="title" id="name-id"> ID {{ item.getRobotName() }}</h2>
<p id="latbot" data-lat="...
0
votes
0
answers
32
views
Symfony DateTime format errors - datatransformation (external datepicker)
I'm working with Symfony 6 and a TempusDomini datepicker.
I have read (amongst many others) the symfony documentation, https://symfony.com/doc/current/reference/forms/types/datetime.html.
Based on the ...
-1
votes
0
answers
33
views
Symfony / twig - Form with master-detail in it .. How to?
I'm coding a master detail page with Symfony 5 and twig
I have table product, and another options
When I create a product, I want to ask for name and have to check options
Example:
Text : Production....
-2
votes
1
answer
32
views
How to set a html attribute + value via ternary?
I've tried countless options, but I never get the quotes to wrap around the entire value as soon as there's a space within the value string:
{% set result_string= elements
? ( "data-...
0
votes
0
answers
36
views
How can i unescape "slash" additionally to basic function {% autoescape false %}?
I'm working on an app with Symfony/Twig, and I want to scan a directory and add all photos of this directory in a Bootstrap carousel.
Controller
public function index(int $id, ManagerRegistry $...
0
votes
0
answers
20
views
How to get a Taxonomy Term ID in Drupal/Twig view
hope you doing well.
I'm starting with drupal.
and i was asked to change a field class when it has a certain value previously defined as default.
if i insert this is the view <p>{{ content....
0
votes
0
answers
96
views
inside a script module, try to import js files with twig asset() (error: myalias.x is not a function)
[ Environment: symfony (PHP), twig files with HTML/JS code, and Managing assets with Webpack ]
Files Tree
_assets
|__js
|__file.js
|__library
|__ps
|__index.js
_public
|...
0
votes
0
answers
43
views
session in symfony works in chrome but not in firefox
Hello I have a problem with my code.
I have coded the game black jack in php, symfony and twig.
When I publish it to our student server it works fine on Chrome but not on firefox.
On my teachers ...
0
votes
0
answers
51
views
Rendering a template with form inside from a service
my DataTable service code is given below
public function dataTableTest(string $class, Request $request, $FormBuilder): Response
{
$FormFactory = Forms::createFormFactory();
$form = $...
-2
votes
0
answers
40
views
Is there a function that acts like {{ }}
I don't know if is there some function to get the rendered text when you do {{ var }}
For example:
{% text = function(var) %}
I need a function that does the same as {{ }}
-1
votes
1
answer
44
views
How to call built-in twig function from custom twig filter?
I want to create a custom filter which will return HTML link to client profile.
I need something like:
<?php
namespace App\Twig;
use App\Entity\Client;
use Twig\Environment;
use Twig\Extension\...
0
votes
1
answer
30
views
Paragraph 2 column layout
Below is my paragraph.html.twig template:
{% block paragraph %}
<div{{attributes.addClass(classes)}}>
<div{{content_wrapper_attributes}}>
{% block content %}
...
1
vote
1
answer
31
views
Convert rows to columns using Twig - D8
I have a content type "Awards" that has data structured as below:
I want to group this data as below:
Want to group them on a "State" basis. So when I click on mysite.com/TXawards,...
1
vote
1
answer
30
views
Symfony Mailer Twig Context in Subject Line
I am using Symfony 5 and the mailer component with twig templating. The context works fine for the body of the email, but is there not a way to apply that to the email subject line also?
Right now I'...
0
votes
1
answer
67
views
Getting the value of a specific input from a list of inputs with the same class
So, I've looked a lot into this and couldn't really find an answer that suited my needs or addressed my issue.
I have a block of html <div>, <span>, <i> and <input> that I ...
1
vote
1
answer
27
views
Calling method in Twig, how to avoid the return showing as output
I am calling a method in a pre-existing object from inside a Twig template, after properly authorizing it in policy:
{{ thisEmail.AddCC('me@example.com') }}
My problem is that the object method, ...
2
votes
1
answer
54
views
How to get media
I'm trying to access the product.media property inside the file /component/product/card/box-standard.html.twig with the following code:
{{ dump(product) }}
But the product.media returns the value ...
0
votes
1
answer
35
views
Map Leaflet, display multiple markers from a loop
I would like to display markers whose latitude and longitude coordinates come from a database. I use a "for" loop to get the positions from the database. I am displaying my map using leaflet....