Symfony 2: Deploy assets from non bundles - symfony

I wonder if there's a possibility to deploy assets from a custom folder.
I've separated my business logic and entities from the bundles and now I would like to have a centralized place to my custom js library.
Is there any configuration available for symfony or assetic to deploy a custom folder that doesn't belong to a bundle? TIA

Well, I found an answer without intention LOL.
Looking a repo on github I saw that Assetic can be configured to receive some input resources and generate a unique output like this:
assetic:
debug: %kernel.debug%
use_controller: true
filters:
cssrewrite: ~
yui_css:
jar: %kernel.root_dir%/../vendor/nervo/yuicompressor/yuicompressor.jar
yui_js:
jar: %kernel.root_dir%/../vendor/nervo/yuicompressor/yuicompressor.jar
less:
node: /usr/bin/node
node_paths: [/usr/local/bin/]
apply_to: "\.less$"
assets:
scripts:
inputs:
- %kernel.root_dir%/../src/MyResources/script.js
- #FoundationViewBundle/Resources/public/js/*
filters:
- cssrewrite
- yui_js
output: js/scripts.min.js
debug: %kernel.debug%
stylesheets:
inputs:
- %kernel.root_dir%/../src/MyResources/stylesheet.css
- #FoundationViewBundle/Resources/public/css/*
filters:
- less
- yui_css
output: css/style.min.css
debug: %kernel.debug%
Which can be used directly with:
<link href="{{ asset('css/style.min.css') }}" rel="stylesheet">
<script src="{{ asset('js/scripts.min.js') }}"></script>
or using Assetic aliases:
{% stylesheets '#stylesheets' %}
<link rel="stylesheet" type="text/css" media="screen" href="{{ asset_url }}">
{% endstylesheets %}
{% javascripts '#scripts' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

Related

In Symfony2 using the AsseticBundle tool, based on the .Less file to create all the .Css files to web directory, the program into an infinite loop?

I can't find the reason. Please help me.
I use this command generate .css file to web directory:
$sudo php app/console assetic:dump
Error information:
[Symfony\Component\Debug\Exception\OutOfMemoryException]
Error: Allowed memory size of 5368709120 bytes exhausted (tried to allocate 4205621120 bytes)
$ls /opt/webroot/symfony/web/css
//views/base.html.twig
{% block head_style %}
{% stylesheets filter='less,cssrewrite'
'#ScourgenPersonFinderBundle/Resources/public/less/style.less'
'#BloggerBlogBundle/Resources/css/style.css'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen"/>
{% endstylesheets %}
{% endblock head_style %}
#app/config/config.yml
assetic:
debug: '%kernel.debug%'
# use_controller: '%kernel.debug%'
use_controller: false
bundles:
- ScourgenPersonFinderBundle
- MopaBootstrapBundle
- BloggerBlogBundle
filters:
cssrewrite: ~
# yui_css:
# jar: /usr/local/lib/node_modules/yuicompressor/build/yuicompressor-2.4.8.jarw
less:
node: /usr/local/bin/node
node_paths: [/usr/local/lib/node_modules, /opt/lessc]

Image assets in css Symfony 2.7

Ok, so I have problem with linking assets ang using path to image in css.
I have assets in src\AppBundle\Resources\public\ I did assets:install and assetic:dump, but I can't link both image and css correctly.
Here is my layout.twig.html from AppBundle\Resources\views
{% stylesheets 'bundles/app/css/*' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}"/>
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/bmatznerfontawesome/css/font-awesome.min.css') }}" />
{% endstylesheets %}
and my config.yml
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ "AppBundle" ]
#java: /usr/bin/java
filters:
cssrewrite: ~
and finally here is my css with background image
background: url('../images/nav_bg.jpg') repeat;
It all works on dev but my main.css from assets is not visible in prod environment however fontawesome link is ok. Path to css in prod env is /web/css/2c8c367.css.
When it should be web/bundles/app/css/2c8c367.css
Thanks in advance for your help.

Symfony2 include js files via loop from assetic.yml

assets.yml:
assetic:
assets:
base_js:
inputs:
- '%kernel.root_dir%/Resources/public/jquery-1.10.2.min.js'
- '%kernel.root_dir%/Resources/public/bootstrap3/js/bootstrap.min.js'
output: 'js/scripts.js'
base_css:
inputs:
- '%kernel.root_dir%/Resources/public/bootstrap3/css/bootstrap.min.css'
output: 'js/styles.css'
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: assets.yml }
#...
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [MyAdminBundle]
#java: /usr/bin/java
filters:
cssrewrite: ~
And in template:
{% block javascripts %}
{% javascripts '#base_js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
However as output I get js/80e3acc_part_1.js and this file only includes the jquery code, boostrap is missing. Any ideas how to fix this?
sadly the output filename configuration of an asset collection is currently not being used by default if none is specified within the {% image %},{% stylesheets %} or {% javascripts %} tag if only one #-resource is present - this explains the filename js/80e3acc_part_1.js.
Further the asset() function does not work with the # - syntax.
use the following to fix the filename issue.
{% javascripts '#base_js' output='js/scripts.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
or just include the output filename directly with the asset() function.
<script src="{{ asset('js/scripts.js') }}"></script>
This syntax is cleaner but leaves the downside of in case having to change the filename in configuration and the template if you want to rename the output file.
Please note that assetic in most cases does not automatically update the resources for cached collections if resources are added. Therefore always clear your cache using app/console cache:clear prior to dumping your assets.
That would explain why bootstrap was missing in the output file after dumping if you added it as second resource but did not clear the cache before using the assetic:dump command.

Assetic Symfony2 less+compress filter

Is there a way to make assetic automatically compile and compress .less files?
I tried this config:
assetic:
debug: "%kernel.debug%"
use_controller: true
bundles: ['BloggerBlogBundle', "FOSCommentBundle"]
#java: /usr/bin/java
filters:
cssrewrite: ~
less:
node: /home/igor/nvm/v0.8.16/bin/node
node_paths: [/home/igor/nvm/bin/node_modules]
apply_to: "\.less$"
yui_css:
jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
apply_to: "\.css$|\.less"
But this results in .css files getting compressed and .less files getting compiled. I can't make it do both: compile and then compress my .less files.
Here is my config and twig code for compiling + compressing .less files in the same time:
config.yml
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
java: %java_path%
filters:
less:
node: %node_base_path%
node_paths: [%node_lib_path%, %node_modules_path%]
cssrewrite: ~
yui_css:
jar: %kernel.root_dir%%jar_file%
yui_js:
jar: %kernel.root_dir%%jar_file%
In my twig:
{% block stylesheets %}
{% stylesheets
'#MyBundle/Resources/public/css/event.less'
'css/colorpicker.css'
filter='less,?yui_css'
output='build/event_layout_2cols.css'
%}
<link href="{{ asset_url }}" rel="stylesheet" media="screen" />
{% endstylesheets %}
{% endblock %}
And here is the command to both compile AND compress:
./app/console assetic:dump --env=prod --no-debug
Hope that help!

Symfony2/Assectic: 500 error when combinding LESS/CSS

When I add a second file to my other file it seems to cause a 500 error on the first one.
{% stylesheets
'#MopaBootstrapBundle/Resources/public/less/mopabootstrapbundle.less'
'#MyTestBundleBundle/Resources/public/css/main.css'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen" />
{% endstylesheets %}
Here is my assetic(it uses controller in dev):
assetic:
debug: %kernel.debug%
use_controller: false
#java: /usr/bin/java
filters:
cssrewrite: ~
less:
node: /usr/bin/node
node_paths: [/usr/lib64/node_modules]
apply_to: "\.less$"
If i remove the main.css it works fine. If I move main.css to a different stylesheets block it also works fine.
I think that you forget about filter attribute.
{% stylesheets '#MopaBootstrapBundle/Resources/public/less/mopabootstrapbundle.less' '#MyTestBundleBundle/Resources/public/css/main.css' filter='less,?yui_css'%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen" />
{% endstylesheets %}
Update.
I saw the apply_to: "\.less$" just now.
Split this block to 2 stylesheets
{% stylesheets '#...less' %}
<link href="{{ asset_url}}" ... />
{% endstylesheets %}
{% stylesheets '#...css' %}
<link href="{{ asset_url}}" ... />
{% endstylesheets %}
The issue was that my less in node was the issue. Switching this to the latest in github (1.3.1) fixed it.

Resources