I have an HTML tag in forum-list.tpl.php file:

<img class="show_hide" src="<?php path_to_theme();?>/expanded.gif" alt="[+]" />

In javascript I need to change the expanded.gif to collapsed.gif. But I don't have a function in JavaScript like "path_to_theme", so I need to tell Javascript about path.

I need to use drupal_to_js() and how? I need to put the function inside JS code?

Comments

WorldFallz’s picture

see http://api.drupal.org/api/function/drupal_add_js/6

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

zoliky’s picture

Sorry I don't want to add JavaScript code in PHP.

Ok...I try to use a regexp I kill my nerve.. I don't understand what drupal_to_js do, I never see a stupid documentation like drupal API. Why API not show an example?

WorldFallz’s picture

My bad-- I misunderstood what you were asking. Have you seen http://drupalcodesearch.com ?? There's several examples of drupal_to_js there. Maybe one of those will be helpful....

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

TruthSHIFT’s picture

Luckily, you can use drupal_add_js() to give jQuery access to the value from path_to_theme(). Try something like this:

<?php

$path = path_to_theme();
drupal_add_js("var path = '$path';","inline");

?>