twig

Run CSS file through Twig when using {% stylesheets %} tag in Twig with Symfony2

a 夏天 提交于 2020-01-12 07:14:01
问题 I'm including CSS stylesheets in my template like so: {% stylesheets "@SomeBundle/Resources/assets/css/default.css.twig" "@SomeBundle/Resources/assets/css/global.css.twig" %} <link rel="stylesheet" href="{{ asset_url }}" /> {% endstylesheets %} However I want to run these CSS files through Twig, is this in any way possible while using the {% stylesheets %} tag or does this require some other approach. I've already tried enabling a twig filter but that does not exist. 回答1: You could do it if

Run CSS file through Twig when using {% stylesheets %} tag in Twig with Symfony2

半腔热情 提交于 2020-01-12 07:13:06
问题 I'm including CSS stylesheets in my template like so: {% stylesheets "@SomeBundle/Resources/assets/css/default.css.twig" "@SomeBundle/Resources/assets/css/global.css.twig" %} <link rel="stylesheet" href="{{ asset_url }}" /> {% endstylesheets %} However I want to run these CSS files through Twig, is this in any way possible while using the {% stylesheets %} tag or does this require some other approach. I've already tried enabling a twig filter but that does not exist. 回答1: You could do it if

twig inheritance and symfony2 controller variables

安稳与你 提交于 2020-01-11 09:50:20
问题 Im trying my first project using symfony2 + twig. I created basic twig template with defined blocks. It basically looks like this {% block content %} some content... {% endblock %} {% block footer %} {{ footer.content}} {% endblock %} I want footer to be same for all pages. Footer is loaded from DB and its set in controller. I wanted inherit from template described above to other pages but I have to always set footer in controller otherwise variable is not defined. My questions is if exists

How to properly enable the twig's sandbox extension in Symfony2?

本秂侑毒 提交于 2020-01-11 07:03:06
问题 In Symfony2, there is some Twig module disabled by default. One of them is the debug extension, that adds {% debug %} tag (useful on a development environment). To enable it, nothing really difficult, you add this service to your configuration : debug.twig.extension: class: Twig_Extensions_Extension_Debug tags: - { name: 'twig.extension' } But how to enable the {% sandbox %} tag? My issue is that the extension's constructor takes security policies : public function __construct(Twig_Sandbox

Pass javascript variable to twig

允我心安 提交于 2020-01-11 05:01:06
问题 I just want to pass a javascript variable to a twig path. Now i'm using this, but it doesn't work. <p id="result"></p> <script> var text = ""; var i; for (varJS = 0; varJS < 5; varJS++) { text += "<a href='{{ path('lesson',{'id': varJS }) }}'>article</a>"; } document.getElementById("result").innerHTML = text; </script> 回答1: for (varJS = 0; varJS < 5; varJS++) { var url = '{{ path("lesson", {'id': 'article_id'}) }}'; url = url.replace("article_id", varJS); text += '<a href='+ url +'>article</a

Symfony2 - get main request's current route in twig partial/subrequest

只谈情不闲聊 提交于 2020-01-10 19:40:37
问题 In Twig partial rendered by separate controller, I want to check if current main route equals to compared route, so I can mark list item as active. How can I do that? Trying to get current route in BarController like: $route = $request->get('_route'); returns null . Uri is also not what I'm looking for, as calling below code in bar 's twig: app.request.uri returns route similar to: localhost/_fragment?path=path_to_bar_route Full example Main Controller: FooController extends Controller{

Get ROLE of a user not logged in TWIG Symfony2

两盒软妹~` 提交于 2020-01-10 08:55:29
问题 I would like to know how can i know if a user is granted when it's not the current user in twig. I use this code for the current user: {% if is_granted('ROLE_USER') %} <a href="...">Delete</a> {% endif %} But i would like to be able to do the same thing with ohter users that are not logged in at the moment. Thank you. Edit: In fact i think there isn't a direct way with twig to test role of a user that is not authenticated. So i did it directly in the twig template, test if a user is admin or

ThinkPHP开发必备composer扩展包

≡放荡痞女 提交于 2020-01-07 06:39:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本文假设读者有能力正常使用composer 环境隔离 dotenv 真实世界的开发往往是这样, 多个团队成员共同开发, 线上线下的代码通过版本控制系统保持一致. 但你无法保证也没理由要求所有机器上的应用配置一致. 例如,要求所有成员使用相同的本地数据库用户名和密码是不合理的. 线上线下使用相同的数据库配置更加不合理. 我们有很多种方式避免这种问题, 一种常见的方法是, 将配置文件重命名为config.example.php, 然后在每个部署的环境再重命名为config.php,并在分发时排除这个文件. 这种方法很容易实现,但缺点是他是静态的. 每当你增加了一项配置, 或者减少了一项配置, 都需要告诉别人手动处理config.php. 否则, 它的程序可能无法正常运行. 通过专门的环境配置区分不同的部署环境,是另一种被广泛采用的方案. 它的原理很简单: 不同的部署环境中, 需要区别的配置往往非常有限, 所有将config.php纳入版本控制或者分发包中更合理. 这样config.php有变化时,其他环境中的应用可以第一时间更新. 那有限的几个有环境有关配置, 往往都是诸如数据库配置这种必不可少的. 将它们单独隔离出来更加合理. 通常, 实施这种方案会把 隔离的配置放在一个名为 .env 的文件中. 因此这种方案,

how to display to a html twig form field value through javascript using an alert message in Symfony2?

房东的猫 提交于 2020-01-07 06:24:13
问题 I would like to know how to display to a html twig form field value through javascript using an alert message in Symfony2. This is the form code: <html> <head> <title> Wkayet </title> <link rel="shortcut icon" href="{{asset('bundles/ikprojhome/images/icon-WKAYET.png')}}"> <link rel="stylesheet" type="text/css" href="{{asset('bundles/ikprojhome/css2/css.css')}}"/> <script src='{{asset('bundles/ikprojhome/lib/jquery.min.js')}}'></script> <script> function f1(){ alert($('#ikproj_groupebundle

Find object by id in an array of JSON objects with Twig

落花浮王杯 提交于 2020-01-07 03:59:49
问题 I am being passed an array that unfortunately I cannot restructure: "options": [ {"name":"namea","text":"valuea"}, {"name":"nameb","text":"valueb"}, {"name":"namec","text":"valuec"}, {"name":"named","text":"valued"} ] I need to be able to find the object with the name equal to namea, nameb, namec, etc. and then produce the appropriate text. I tried the following and few other variations of that but could not get it to work: {% for item in event.options %} {% if item.name == "nameb" %} {{ item