preg_replace space to line break with twig

Twig
I would like to replace space in string to line break. Before 1 2 3 4 After preg_replace : 1 2 3 4 This is my code: $m_cart = preg_replace('/\...
4 months ago

What is the correct way to concatenate and trim in TWIG

Twig
I'm new to TWIG. I can do this in PHP, but I'm looking for the right way to do it in the template using TWIG. Controller code: public function inde...
5 months ago

Twig - display template names if debug mode is enabled

Twig
I'm using Twig lately and I was wondering if it is possible to output the template names which are loaded on the page. The best way I can think of is ...
5 months ago

php namespace class not found - twig composer

Twig
I searched and tried all the answers and have had no success. I have a small MVC that was working just fine till I added namespaces. Errors everywher...
5 months ago

Twig: remove div around each checkbox fields of a form

Twig
Edit: see the solution I've found at the end of my question ;-) I'm looking since hours for a solution but I do not really find what I'like. I'm sur...
5 months ago

Form tag attributes in Symfony2 / Twig

Twig
When I want to add some attributes to symfony2 form elements I can just use the "attr" attribute. But how can I give some id / class / style / other t...
5 months ago

How to insert a Controller in Twig with “render” in Silex

Twig
Should it work in Silex with symfony/twig-bridge ? {{ render(controller('MyController')) }} Now I have message like this: Twig_Error_Syntax: Th...
4 months ago

php twig get variables passed to render in extension function

Twig
I swear I've googled this and tried to understand the docs, but I'm just not getting it. I'm writing a twig function, what I can't understand is how I...
4 months ago

Setup twitter bootstrap, in slim php, after downloading via composer?

Twig
I've installed twitter bootstrap via composer and don't have any idea how to reference it in a twig view. I suppose there's a namespace for it but I d...
4 months ago

How to use php json_encode options in twig file with json_encode twig function

Twig
I am trying to use twig json_encode function but when I do this var packageDetails = {{(packageDetails|json_encode)}}; and packageDetails is a...
4 months ago

How to get config parameters in Symfony2 Twig Templates

Twig
I have a Symfony2 Twig template. I want to output the value of a config parameter in this twig template (a version number). Therefore I defined the co...
5 months ago

Use loop.index as part of template name to include with Twig?

Twig
I have an array of 3 items so in the following I'm including sub-component.twig 3 times: {% for i in array %} <div class="my-class"> {% ...
5 months ago

How can I detect if a form has any elements left to be rendered?

Twig
Let's say I am using the Symfony Form Component to render a simple form with only two fields (username and email) I am rendering both fields with for...
5 months ago

Sending variable from volt to custom function

Twig
I have created a custom function I can access from the volt. The function seems to work fine, but I cannot manage to send the variable to the function...
5 months ago

document.write javascript function is not working

Twig
I'm trying to use the document.write javascript function to set an external css file in my template, but, I want to do this via Twig just like this: ...
5 months ago

Symfony2 creating twig extension

Twig
I want to create a simple twig extension ({{imgWidth(...)}}) that calls getimagesize() and returns the width and height of an image on the server. I ...
5 months ago

Can an object tell Twig not to escape output when it is {{ printed }}

Twig
I've got a situation where some variables sent to my Twig templates are plain old variables, so I want them to be html-escaped (as is the default beha...
4 months ago

Symfony-Twig: insert fontawesome icon in a form_widget

Twig
To validate a form I am using a standard: {{ form_widget(form.save, {'attr': {'class': 'btn btn-sm btn-danger'}, 'label': 'Submit form'}) }} I want...
4 months ago

Twig check if value in array is true

Twig
I have an array which contains booleans. How do I search the array to see if one or more is true and then display the something once? Here is my co...
4 months ago

Append onto current URL with Twig?

Twig
I'm currently making a simple file hosting script using Slim, Twig, and PHP. Right now I'm trying to append onto the current URL using Twig but am not...
4 months ago