Top menu

How to truncate String by Words

If you simply want to truncate text to a certain number of words, because you do not want a word will be cut, the code below will do the trick:



Add param in URL

In the function below, I will show you how to add a parameter in URL by treating all possible cases : first check whether the parameter is already defined in the URL so that we can just update it if parameter is already defined in the URL, so replace the parameter value, rather than append […]


Enable the debug extension in Twig

To enable the debug function in twig. You have to modify the file app/config_dev.yml by adding the code below :

Then in your twig file (ex : test.html.twig) : {% debug %} => Display all variables assigned to the template engine for the view in question {% debug var %} => Displays information about […]


Remove additional_settings from node add/edit form

When printing a form in Drupal, it has the right to display an area to define more advanced settings. This useful area when a director and totally useless for visitors (see dangerous): There are certainly several ways to remedy this problem, but I suggest you mine which seems clean, just change the forms no longer […]


How to get the URL for an image style derivative

To get the URL of an image after applying a particular style on the original picture, it is very simple just use the function below :

Here is an example to use this function :

So we get in the variable $ picture_path the url of the image on which we apply the […]


Concatenate a value when updating mysql field

In this post we will show how update string field by concatenating to it? i need a simple query which update mysql field with its value and some modification for example if field have value (3,4,5) i can add (,6) and this just in case it have value and if its NULL then update the […]


How to insert a block into a node or template in Drupal 7


$block = module_invoke(‘simplenews’, ‘block_view’, ’24’);


How do I redirect a form after has been submitted


OR :



Get drupal installed document root

To get the complete base path where the Drupal site is installed you can use:

On a Ubuntu system you will get something like:

If you only use “base_path()”, you will obtain only:


Add attribute to field form