Hi,

I'm a complete newbie to Drupal and PHP and would like some assistance in getting some basic php working.

In a tpl.php file I'm trying to create a link depending on a category and I can't seem to get the a href to work.

Here's my code:

switch ($node->field_cc_resource_category[0]['view'])
  	  {                   
        case "Interview Preparation":
            $button = "<a href="../book-appointment"> Book an Appointment for Interview tips </a>";   
            break;                       

        case "Resume Consultation":
            $button = "<a href="../book-appointment"> Book an Appointment to Enhance your Resume </a>";   
            break;                       
                
    }
?>

Any help is greatly appreciated.

Thanks

Comments

kbr’s picture

switch ($node->field_cc_resource_category[0]['view'])
    {                   
        case "Interview Preparation":
            $button = "<a href=\"../book-appointment\"> Book an Appointment for Interview tips </a>";   
            break;                       

        case "Resume Consultation":
            $button = "<a href=\"../book-appointment\"> Book an Appointment to Enhance your Resume </a>";   
            break;                       
                
    }
?>

You should also look into t() and l() functions anytime you deal with strings.

manila555’s picture

Awesome Thanks!

I didn't realize that I needed a "\" for the "a href" tag.

Interesting.

nevets’s picture

Instead of

            $button = "<a href="../book-appointment"> Book an Appointment to Enhance your Resume </a>";   

you can try

            $button = l(t('Book an Appointment to Enhance your Resume'), 'book-appointment');   

In general terms the function l() takes several arguments. The first is the link text, the second the Drupal path. The t() function allows the text to be translated.

manila555’s picture

Great explanation! Thank You!

CMS’s picture

hi manila555
could u please describe what result your getting out of the above code.
and
If "Interview Preparation" and "Resume Consultation" are the only 2 possible values that $node->field_cc_resource_category[0]['view'] can hold then why not use an 'if ... else' statement .