Questions tagged [twig]

Twig, the cutting-edge templating engine for PHP, embodies a versatile, quick, and protected approach to modern web development. Initially designed for Symfony, this innovative tool has garnered widespread recognition among Drupal 8 users as well.

What is the correct method for embedding a javascript variable into a Twig path?

I am looking to include a variable declared in JavaScript into the path for redirecting my page. Here is my code: var id = $(this).attr('data-id'); windows.location = {{ path("mylink", {id: id}) }}; Unfortunately, I am getting an error when trying to ...

Using a twig loop to display just a single table cell

The following twig loop is used to generate data: {% for reservationDate, rooms in data.pricingTable %} <tr> <td> {% for room in rooms %} <tr> <td ...

Using TWIG to Load Files Remotely

When working with Symfony 2.3 and Twig, I am facing the challenge of selecting remote assets within a Twig template. Within my Twig template, I have a body block structured like this: {% block body %} {% include 'http://asset.remotelocation.co.uk/tem ...

Combining data from two tables with a join query, followed by displaying the results in

1) cms 2) cms_translations cms id url status cms_translations object_id title lang_id I have also created a cmsRepository file for handling this. $q = $em->createQuery("SELECT c , d FROM Dashboard\CmsBundle\Entity\Cms c JO ...

Prevent Symfony2 Twig from rendering HTML content

Is there a way to disable the rendering of HTML responses in Twig? I am currently working on a RESTful API and my goal is to completely prevent HTML rendering. For instance, if I access /foo/bar without an oAuth Access Token, Symfony2 should reply with a ...

Leveraging JS Variables within Twig Template

I am trying to incorporate a JavaScript variable into Twig. Despite attempting to implement the solution mentioned here, my code below does not render the map properly. If I remove the part between "var polylineCoordinates" and "polyline.setMap(map);", th ...

I'm searching for the icon list within Shopware 6, where could it be located?

Is it possible to include an icon in a post using the sw_icon command? For instance: {% sw_icon 'head' %} Are there any alternatives to using 'head' for this command? ...

Identify and address issues with undeclared Twig variables

When a Twig template contains an unset variable, the outcome is determined by the setting of strict_variables. There are two options available: false (default): The variable is treated as NULL, and the template continues to render. true: An exception is ...

Send a JavaScript variable to Twig

I am trying to pass a JavaScript variable to a twig path but the current method I am using is not working as expected. <p id="result"></p> <script> var text = ""; var i; for (varJS = 0; varJS < 5; varJS++) { text += "<a href= ...

Incorporating form fields for editing into Symfony 2's database

Can someone help me troubleshoot my issue with Symfony2? I'm new to this framework and struggling with a problem in my twig file. I have a form where I enter a test name and the names of its categories, along with a color for each category. However, w ...

When the result of Ajax is identical to that obtained without Ajax, the innerHTML remains the same

I understand that utilizing innerhtml is generally considered a poor practice due to the potential for XSS vulnerabilities (). However, consider the scenario below: I have a webpage generated through a Twig template called index.html.twig. When using te ...

Discover the power of Shopware 6 with the sw-inherit-wrapper feature for the sw-snippet-field and sw-media-field components in Vue.js

Currently, I am developing a custom administration module (plugin configuration) in Shopware 6 using Vue.js. An issue I am facing is the absence of an inherit wrapper that appears when there is a change in the sales channel. My goal is to replicate the s ...

Converting an array into a string, transitioning from PHP to JavaScript

Hey everyone, I'm currently working on passing an array to a JavaScript file and encountering this error: An exception has been thrown during the rendering of a template ("Notice: Array to string conversion"). What I need is: data: ['2017/7','2017/8'] ...

Using Twig: Transfer the content of a textfield as a parameter in the routing

I have a task of redirecting to another page while passing along the value from a textfield. Here is my current code: {% extends "base.html.twig" %} {% block body %} <button onclick="host()">Host the session</button> <button onclic ...

FormBuilder Interface Silex File Input

Having recently subscribed, I have come to seek assistance on a platform where I have previously found many solutions to my issues. I have completed a course on Openclassrooms (Transitioning to a Professional PHP Architecture) which has equipped me with t ...

What is the proper way to format lengthy lines in Twig templates while adhering to coding standards?

In my templates, I have the following code snippet for generating routes with parameters: <a class="btn btn-block btn-abcd" href="{{ path( 'auth.login', { 'type': constant('User::TYPE_CANDIDATE'), 'provider': constant('UserProvi ...

"Instead of encountering a fatal error, imagine stumbling upon a blank Twig

I am facing a situation where using Twig results in a blank page instead of showing a fatal error. I understand that this is related to the error reporting settings, and I have to explicitly set it to E_ALL for it to function properly. I have implemented ...

Using Icons in a Symfony ChoiceType Field

In my Symfony Form, I am attempting to display a SelectField with various icons. Here is what my ChoiceType looks like: ->add('icon', ChoiceType::class, [ 'choices' => [ '' => '', '' = ...

Exploring the possibilities of accessing $_SESSION within Craft CMS version 3.x

Can you access the $_SESSION variable in a .twig template in Craft CMS version 3.x? I've come across articles for version 2.5 but nothing specific to 3.x and above. Appreciate any help on this matter. Thanks. ...

Is there a way to determine if a button was clicked using twig?

I need assistance with implementing a button in my twig file within a table that will remove an element from an array. Ideally, I would like to remove the element based on its index. From the research I have conducted, it seems that data manipulation shou ...

"Transferring a JavaScript variable to Twig: A step-by-step guide for this specific scenario

When it comes to loading a CSS file based on the user's selected theme, I encountered an issue while trying to implement this in my Symfony application using Twig templates. The code worked flawlessly on a simple HTML page, but transferring it to a Twig te ...

What is the process for adding a counter variable to a field within a Twig file?

I'm working on a Twig file where I need to create a table and populate it with data using a loop. The issue is that all my field names are the same, so I want to add a counter variable to differentiate them. How can I achieve this? Below is the code ...

Symfony 4 Forms: Enhancing User Experience with Prototypes

Recently, I've delved into Symfony 4 and encountered an issue with rendering a form featuring a ChoiceType Field with numeric choices. The goal is to allow the user to select a specific number of tags. Here's a snippet from my controller: class ...

What is the best way to craft an if/else statement for a situation when a twig variable is undefined?

When utilizing twig to declare a variable called user: <script type="text/javascript> {% if user is defined %} var user = { example: {{ userjson | raw }} }; {% endif %} </script> If a user is not logged in, an error message a ...

Is it required to set a $basepath when incorporating Twig with Slim 3?

Currently, I am utilizing the Twig-View feature of Slim framework from https://github.com/slimphp/Twig-View, to render Twig templates within my application. The detailed instructions provided on the respective pages make the integration process quite stra ...

Exploring Twig variables in Node.js with the node-twig package

Despite following the documentation meticulously, and experimenting with various methods, I am still unable to achieve success. I have attempted using the code snippet below, trying to reference the variable in the main file like this: // None of the opti ...