yet another lighthouse for Linux geeks and code monkeys
Software Tips & Tricks
Assetic in SmartyBundle
Mar 31st
Being an “unofficial” template engine in Symfony2, Smarty(Bundle) needs to catch up with its Twig and PHP counterparts to provide the same integration and range of features. One of the features missing in SmartyBundle was until recently Assetic.
Assetic
Assetic is an asset management framework for PHP written by Kris Wallsmith. Although this library is available for every PHP project I’m focusing in Symfony2 integration.
For a complete overview of the usage of Assetic in Symfony context please refer to the following cookbook entries:
- Symfony2 – How to Use Assetic for Asset Management
- Symfony2 - How to Minify JavaScripts and Stylesheets with YUI Compressor
Usage in SmartyBundle
SmartyBundle provides the same javascripts, stylesheets and image functions supported in Twig and PHP engines. Usage is quite similar to Twig.
Javascripts
assets='@AcmeFooBundle/Resources/public/js/*'
}
<script type="text/javascript" src="{$asset_url}"</script>
{/javascripts}
Stylesheets
To bring in CSS stylesheets, you can use the same methodologies seen in this entry, except with the stylesheets tag:
assets='@AcmeFooBundle/Resources/public/css/*'
}
<link rel="stylesheet" href="{$asset_url}" />
{/stylesheets}
Combining Assets
You can also combine several files into one. This helps to reduce the number of HTTP requests, which is great for front end performance. It also allows you to maintain the files more easily by splitting them into manageable parts. This can help with re-usability as you can easily split project-specific files from those which can be used in other applications, but still serve them as a single file.
Using the same javascripts example as above. Note the usage of commas to separate assets.
assets='@AcmeFooBundle/Resources/public/js/*,
@AcmeBarBundle/Resources/public/js/form.js,
@AcmeBarBundle/Resources/public/js/calendar.js'
}
<script src="{$asset_url}"></script>
{/javascripts}
In the dev environment, each file is still served individually, so that you can debug problems more easily. However, in the prod environment, this will be rendered as a single script tag.
Block attributes
Here is a list of the possible attributes to define in the block function.
- assets: A comma-separated list of files to include in the build (CSS, JS or image files)
- debug: If set to true, the plugin will not combine your assets to allow easier debug
- filter: A coma-separated list of filters to apply.
- combine: Combine all of your CSS and JS files (overrides `debug`)
- output: Defines the URLs that Assetic produces
- var_name: The variable name that will be used to pass the asset URL to the <link> tag
Full example
And now here goes an example using all available attributes:
assets='@AcmeFooBundle/Resources/public/js/*,
@AcmeBarBundle/Resources/public/js/form.js,
@AcmeBarBundle/Resources/public/js/calendar.js'
filter='yui_js'
output='js/compiled/main.js'
var_name='js_url'
%}
<script src="{$js_url}"></script>
This is work in progress
That’s right, Assetic support in SmartyBundle still requires some real world usage to get rid of its sharp edges and bring it to production level. If you are able to give it a try, test it for a bit and bring your complains over to SmartyBundle issue tracker. I’ll appreciate it!
Meme Miner: the translation tool I've been looking for
Mar 14th
No, this will not replace Google Translate or Babel Fish. But it does something that these tools simply can’t offer.
For some time I’ve been using Wikipedia to translate expressions that a normal translator couldn’t give exact results, because they use literal translations. Now there is a faster way.
MemeMiner, brought to us by Fred Rocha, is a Web tool that does this work and gives us a easy and fast way to get this translations.
From the author own words:
For most of it’s articles, Wikipedia provides the equivalent expression of that concept in other languages.
With MemeMiner you can effortlessly find out how a certain idea is expressed across the language spectrum.
Now go ahead and try this tool at http://fredrocha.net/MemeMiner/
Thanks Fred!
Mark all messages as Read in Gmail (in 3 easy steps)
Feb 21st
Want to get rid of all those unread messages in Gmail? Or, just like me, have some unread messages you can’t find and want to reset the unread count to zero? Well, here is the solution:
- Step 1: Type “is:unread” in the search bar.
- Step 2: Then select “Unread” as seen in the picture below.

Type "is:unread" in the search bar and then select "Unread" from the selection bar

In the "More actions" dropdown select "Mark as read"
And that’s it. Your inbox shouldn’t be reporting any unread messages by now.
