How to use the official zurb foundation bundle for symfony2? - symfony

my question may seems really pointless or I may look like an idiot, but I'd like to use Zurb Foundation in Symfony2.
I saw a little number of topics about it, but never an real a clear explanation on how to integrate it properly in my project.
I saw an official bundle on packagist. I installed it so. But there is no documentation for using it with symfony2. For example, how to call my css and js files ? From the vendor folder directly ? How to use compass in my symfony project to use it ? Should I use bower directly ? (this seems to me less painfull) And if yes, if I have an already existing Symfony2 project, may I use bower in the root of my project ? in web folder ? anywhere else ?
I'm really lost and would be greatfull if someone could explain me or give me some resources to help me out.
Thanks

For my website I put all my JS/CSS files in vendor NameVendor
In my layout
{% javascripts
'http://code.jquery.com/jquery-2.1.0.min.js'
'#NameBundle/Resources/public/js/*' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% stylesheets
'#NameBundle/Resources/public/css/*'
filter='cssrewrite' output='css/*.css' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
In script tag
$(document).ready(function(){
$(document).foundation();
});
In App/config/config.yml
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ NameBundle ]
filters:
cssrewrite: ~
I failed to use grunt to update my files so do it manually

https://github.com/florianbelhomme/FlobFoundationBundle
I think that's what you're looking for?

Related

Symfony3 & Assetic : different behavior in dev or prod

I'm working on Symfony 3.4 and Assetic.
Let's say my website is www.mycompany.com and i'm using 2 particular types of asset :
Google web font via #Import() in my main CSS file
Custom CSS fonts, with font files manually uploaded in in web/fonts/
When i visit my website in dev mode www.mycompany.com/app_dev.php/ :
Google fonts are well loaded and work.
Font awesome doesn't work (beacause app_dev.php/fonts/ is 404)
When i visit my website in prod mode www.mycompany.com/ :
Google fonts doesn't work (#import seems not to be loaded...)
Font awesome work (because css files are found in www.mycompany.com/fonts/)
Why this behavior ? For your information, i use Assetic this way to load myu assets :
{% stylesheets '#PimInterfaceBundle/Resources/public/css/*' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
// Same for JS
Thanks.
When using the cssrewrite filter, don't refer to your CSS files using the #XxBundle syntax.
try this
{% stylesheets 'bundles/piminterface/css/*' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
here is doc
Including CSS Stylesheets
Fixing CSS Paths with the cssrewrite Filter
Dumping Asset Files in the prod Environment
if this is not working for you then try php bin/console asset:install
in prod php bin/console assetic:dump --env=prod --no-debug
`

Asset_url in production environment Symfony 3

I have this doubt about URLs of assetics who I generated.
On the view, this was what I did:
{% block stylesheets %}
{% stylesheets
'assets/vendor/bootstrap/dist/css/bootstrap.min.css'
'assets/vendor/font-awesome/css/font-awesome.min.css'
'assets/vendor/dist/css/*.css'
output = 'bundles/compiled/css/app.css' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
{% javascripts
'assets/vendor/jquery/dist/jquery.min.js'
'assets/vendor/bootstrap/dist/js/bootstrap.min.js'
'assets/vendor/dist/js/wow.min.js'
'assets/vendor/dist/js/slider.js'
'assets/vendor/dist/js/jquery.fancybox.js'
'assets/vendor/dist/js/owl.carousel.min.js'
'assets/vendor/dist/js/main.js'
'assets/vendor/dist/js/modernizr-2.6.2.min.js'
output = 'bundles/compiled/js/app.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
In dev environment, the app doesn't call these outputs links who assetic:dump generate, which is:
bundles/compiled/css/app.css
and
bundles/compiled/js/app.js/
both after /web folder.
In prod, I can't reach these locations. I get and 404 on
http://link.com/bundles/compiled/css/app.css for example.
So, how can I configure my config.yml for reach that path in prod environment?
This is what I have:
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
**Edit:**I figured out the problem. My assetic's config was alright, the problem was in VirtualHosts file (modrewrite line, to be specific), which was only accepting ".php" extension files and web/ folder permissions.
That's the whole point of using AsseticBundle! When you are in prod mode, you need to dump the asset files. Have a look here.
php bin/console cache:clear --env=prod //clear the cache for prod environment
php bin/console assetic:dump --env=prod --no-debug
The result will be the concatenation of all your css stylesheets, in one single result file (bundles/compiled/css/app.css), and the concatenation of all your js scripts in one single result file (bundles/compiled/js/app.js), for the reason of reducing the requests to the server.
At this point, you won't be able to see, in the source of the page, all the css + js files, except those two from your compiled/ directory.
When you are in dev mode, the default behavior of AsseticBundle is to generate all your css + js files, for debugging purposes. That is, to help you debug your code easily. So at this point you will be able to see all you css+js files, but not the two files from compiled/ directory.
And pay attention, as cssrewrite must be a child of filters. See here the correction you need.

Assetic creates wrong path in template

Im am using Symfony 2.5.3 with Assetic Bundle 2.5.0. Assetic keeps generating wrong urls to generated asset files.
My config_dev.yml looks like this:
assetic:
use_controller: false
write_to: %kernel.root_dir%/../web/dev/dev-env/
When I run php app/console assetic:dump --env=dev the files are correctly written to the above configured directory.
However, in the twig template, the output is like this:
<script src="/js/7cca762_part_4_timer_2-33c923b.js"></script>
<script src="/js/7cca762_part_4_uploader_3-6336104.js"></script>
when it should be
<script src="/dev/dev-env/js/7cca762_part_4_timer_2-33c923b.js"></script>
<script src="/dev/dev-env/js/7cca762_part_4_uploader_3-6336104.js"></script>
The twig template looks like this:
{% javascripts
'#AcmeProjectBundle/Resources/js/*' filter='?uglifyjs2'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
Any ideas?
Update:
I just found this Stackoverflow item describing the same problem - also without a clear solution so far.
try out asset base urls
framework:
templating:
assets_base_urls:
http: your.url.com/dev/dev-env

Using CDN when combining assets with Symfony2 and Assetic

I would like to use CDN together with Assetic in my Symfony2 project. I am using the javascripts helper to combine several Javascript files:
{% javascripts
'#MyBundle/Resources/public/js/file-1.js'
'#MyBundle/Resources/public/js/file-2.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
and in my config.yml file I have registered a CDN to be used in the assets:
framework:
templating:
assets_base_urls:
http: [http://my.cdn.url]
ssl: [https://my.cdn.url]
When dumping, I do get a combined file, but its url is a relative one, not one pointing to the CDN. For instance:
<script src="/js/c713f83.js"></script>
And the same happens when combining several CSS files. The only way I managed to get URLs using the CDN is through asset:
<img src="{{ asset('bundles/mybundle/images/logo.png') }} ">
Is there anything preventing Assetic from using the CDN hosts I have specified in my configuration?
You have to pass the Assetic's generated asset_url to the asset() Twig's function :
{% javascripts
'#MyBundle/Resources/public/js/file-1.js'
'#MyBundle/Resources/public/js/file-2.js' %}
<script src="{{ asset(asset_url) }}"></script>
{% endjavascripts %}
Be aware that in dev environment you will get URLs that look like http://my.cdn.url/app_dev.php/js/file-1.js. In order to prevent that you have to configure your dev environment so it doesn't use CDN :
# app/config/config_dev.yml
framework:
templating:
assets_base_urls:
http: []
ssl: []
Remember dumping your assets with assetic:dump and, overall, remember that Assetic and the Symfony2 asset Twig function are two different things.

Symfony2 and Assetic - Images referenced in my CSS won't load

I have a CSS sprite sheet I'm trying to use, but my CSS file cannot 'see' the image. I've followed the answer provided here to no avail. My bundle structure is:
src/
vendor/
project/
bundle/
Resources/
public/
css/
normalize.css
static.css
images/
sprites.jpg
I've already done:
$ app/console assets:install
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for MajorProductions\SewingDiva\SiteBundle into web/bundles/majorproductionssewingdivasite
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
and:
$ app/console assetic:dump
Dumping all dev assets.
Debug mode is on.
22:19:13 [file+] /home/kevin/www/diva/app/../web/css/06758be.css
22:19:13 [file+] /home/kevin/www/diva/app/../web/css/06758be_part_1_normalize_1.css
22:19:13 [file+] /home/kevin/www/diva/app/../web/css/06758be_part_1_static_2.css
Not sure what else to do....
Solved it by changing the reference from:
{% block styles %}
{% stylesheets '#MajorProductionsSewingDivaSiteBundle/Resources/public/css/*' filter='cssrewrite' %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
to:
{% block styles %}
{% stylesheets 'bundles/majorproductionssewingdivasite/css/*' filter='cssrewrite' %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
Apparently the auto-magical reference in the first version is not the way to go, despite it being used in the official Symfony docs.
#KevinM1
Apparently the auto-magical reference in the first version is not the way to go, despite it > being used in the official Symfony docs.
It is here (in French, but equivalent doc for other languages certainly exists)
Well, from the documentation:
This is a key point: once you let Assetic handle your assets, the files are served from a different location. This can cause problems with CSS files that reference images by their relative path. However, this can be fixed by using the cssrewrite filter, which updates paths in CSS files to reflect their new location.
So you need to enable the cssrewrite filter:
# app/config/config.yml
assetic:
filters:
cssrewrite: ~
And use it in your stylesheets block:
{% stylesheets '#AcmeProjectBundle/Resources/css' filter='cssrewrite' %}
<link href="{{ asset_url }}">
{% endstylesheets %}

Resources