Assetic을 사용하여 조건부로 자산을로드 할 수 있습니까?Assetic을 사용하여 조건부로 리소스로드
예를 들어 (peusocode) :
이load resource1.js
load resource2.js
if condition = true
load resource3.js
endif
output combined.js
Assetic을 사용하여 조건부로 자산을로드 할 수 있습니까?Assetic을 사용하여 조건부로 리소스로드
예를 들어 (peusocode) :
이load resource1.js
load resource2.js
if condition = true
load resource3.js
endif
output combined.js
assetic 파일이 서버 측에서 컴파일되기 때문에 아니, 할 수없는, 그래서 assetic 런타임에 변수의 값에 액세스 할 수 없습니다.
해결책은 내가 정확히 같은 문제에 걸쳐 온
// the first assetic tag
{% if condition %}
// an other assetic tag
{% endif %}
두 번째 assetic 태그를 추가 할 수 있습니다. julesbou 이미 언급했듯이 여러 assetic 태그를 추가해야합니다. PROD 환경에 대한 DEV 환경에 대한 밝은 회색, 흰색 :
내 특별한 경우의 시나리오는 서로 다른 환경 에 따라 배경을 렌더링하는 것이었다.
{# Common CSS stylesheets--------------------------------#}
{% stylesheets
'@XStitchPublicBundle/Resources/public/css/basic.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{# ----------------------------------------------------- #}
{#
Conditional CSS stylesheet. Depend on the environment
#}
{% set environment = app.environment %}
{% if environment == 'dev' %}
{# Condition: Dev environment#}
{% stylesheets
'@XStitchPublicBundle/Resources/public/css/debug.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endif %}
: 이것은 HTML5에 대한 나뭇 가지 템플릿 태그 내에서 (심포니 2) (내 솔루션입니다 basic.css 및 debug.css :
나는 두 CSS 파일을 사용