I'm trying to build this:

<a href="/en/webform?edit[submitted][nameofthepet_webform_fieldset][webform_nume_animal_comp]=NAME-OF-PET" class="btn btn-primary btn-xs">Adopt NAME-OF-PET</a>

the code I'm using:

$adopt_me_link_male = l(t("Adopt !name",
 array('!name' => $node->field_pet_name['und'][0]['safe_value']), array('context' => 'Male pet name')), 'node/163', array('query' => array('edit[submitted][nameofthepet_webform_fieldset][webform_nume_animal_comp]=' => $node->field_pet_name['und'][0]['safe_value'])), array('attributes' => array('class' => array('btn', 'btn-primary', 'btn-xs'),),) );

The above code generates the link but I have two problems:

  1. the link looks like this:

    Adopt NAME-OF-PET

  2. there's no css class applied to the anchor

Why the classes are not applied and the link looks so messy?

Thank you!


There is a bug in your URL snippet (syntax error), so I'm writing the code.

$adopt_me_link_male = l(
  t('Adopt @name', 
    array('@name' => $node->field_pet_name['und'][0]['safe_value']), //t() function replacements array
    array('context' => 'Male pet name') //t() function options array. Not necessary in this case though.
  'node/163', // l() function - URL
    'query' => array(
      'edit[submitted][nameofthepet_webform_fieldset][webform_nume_animal_comp]' => $node->field_pet_name['und'][0]['safe_value'],
    'attributes' => array(
      'class' => array('btn', 'btn-primary', 'btn-xs'),


In this example, I changed !name to @name for the security (Read t() function documentation). Also, if you want to use HTML inside the anchor (say, an image), you have to pass 'html' => TRUE the last parameter array in the l() function (add it along with the attributes and query array keys).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.