Silverstripe remove CustomScript

Silverstripe Tip of the week:

Sometimes you have to remove a customScript of a module, because you want to script it differently.

If the module author was so wise to give his customScript a ID (UserFormsValidation in this case) like they did in UserForms:

Requirements::customScript(<<<JS
    (function($) {...})(jQuery);
JS
, 'UserFormsValidation');

then you can do the following in the init function of your subclass controller:

Requirements::block('UserFormsValidation');

Easy, isnt it?

Silverstripe RedirectorPage open external Link in new window

Silverstripe Tip of the Week:

If you want to open a “Other website URL” Link of a RedirectorPage in a new window with target=_blank, you can use the following snippet:

<% if ExternalURL %>
   <a href="$ExternalURL" class="external" target="_blank">$MenuTitle.XML</a>
<% else %>
   <a href="$Link">$MenuTitle.XML</a>
<% end_if %>

Edit:
Or this one:

<% if is_a(RedirectorPage) %><% if RedirectionType = External %>target="_blank"<% end_if %><% end_if %>

found here: http://www.silverstripe.org/general-questions/show/9600

Hope it Helps!

Symfony2 from YAML to XML configuration

Actually i was a fan of YAML regarding the configuration files of Symfony2.
This was probably because i was used to it since symfony 1.4 and i also thought its better readable.
Its partly still true, but my Netbeans Editor has some problems with using @ in YAML and this breaks my highlighting.
So the better readability vanished to nirvana.

So i checked out XML configuration. Its also widely used by the community.
Pros and Cons (mostly Pros) you can read in this post by Fabien.

Continue reading “Symfony2 from YAML to XML configuration”

Check if a country is an EU country in Magento

I you ever wondered how you can check if a Country, resp. a Country Code, is in the EU, i did the following:

Magento has a config value: eu_countries that lists all Countries of the EU.

You can find it in the backend under:
Configuration -> General -> Country Options.

Against this list you can validate your country code, f.e. that you got in an billing or shipping address of an order.

Continue reading “Check if a country is an EU country in Magento”

Caching Data in Symfony2

Symfony2 has a great Caching Layer based on its HTTP Cache. But this aims mainly on caching the views.

In some apps however you need to cache data behind the scenes, f.e. responses from API calls or custom objects sets.
Symfony2 itself doesnt have such a functionality on first sight (symfony2 doesnt, but Doctrine, see below) and so I searched for one and first found a bundle which utilize the Zend Cache lib:
https://github.com/KnpLabs/KnpZendCacheBundle

This worked well but as discussed here(https://github.com/KnpLabs/KnpZendCacheBundle/issues/2) this adds dependencies to your Symfony2 project. This is actually not necessary since Doctrine/Commons is almost always part of your Symfony2 distribution and the Doctrine/Commons provides a Cache Layer as well.
A very good one, indeed.

So if you need to cache data use Doctrine/Commons.
Continue reading “Caching Data in Symfony2”

Opengraph MetaTags in SilverStripe

First off some general thoughts on how to use opengraph metatags.
Since the uprise of Social Media, sharing sites, deeplinking and snippetting content has become a important aspect of SEO and so almost every site has some kind of facebook-like-button to let user easily share the page.
Most sharing endpoints, facebook f.e, bring a more or less good parser/linter to summarize the page content. So the first text paragraph will be taken as text snippet and all images that fit certain requirements will be offered to chose a preview-thumbnail from.
So far so good.
Continue reading “Opengraph MetaTags in SilverStripe”

javascript benchmarking with jsperf

I might be a bit late (yeaikno it exist over a year now and a bunch of blogs had it covered) but nevertheless i would like to point out a very helpful online tool i recently ran into:

jsPerf

Its basically a online benchmark tool for testing different approaches in javascript.
It covers some important aspects of benchmarking, that your homemade bench probably wont have like milliseconds accuracy & statistical analysis.
The tests are run on your browser and the results will feed the “browserscope”. A graph of the “highest known results” for the participating browsers.
So we can see some kind of comparison.
Continue reading “javascript benchmarking with jsperf”