Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

It seems most likely that the following code is not working due to bad php but I just can't understand why. If I var_dump $variables['classes'] it returns that it is an array with the classes listed in it beautifully.

I debugged the $item and returns very nicely what I want as well. Then why don't these things get added to my $variables['classes-array'];?

    <?php

function mytheme_preprocess_html(&$variables) {
    dsm($variables);
    $path = url($_GET['q']);
    dsm(var_dump($variables['classes_array']));
    $path_items = explode('/', $path);
    foreach ($path_items as $item) {
        array_push($variables['classes_array'], $item);
    }
}

also tried array_push($variables['classes_array'][], $item);

share|improve this question
Just a note, I think the Devel module suggests you use dpm over dsm at this point in time. – Lester Peabody Mar 26 at 21:17
Also when you're running dsm you're outputting the $variables array before you've made changes to it. – Lester Peabody Mar 26 at 21:22
1  
Yes exactly that was the problem :s. I kept checking the dsm output instead of looking at the html. There classes where in the html the whole time. I lost enough time on this to hopefully learn to never do it again – Immers Mar 26 at 21:33
Lesson well learned :) Trust me, we've all learned it, and forget it from time to time. – Lester Peabody Mar 26 at 21:35
It's reassuring to hear that :) – Immers Jun 26 at 9:36

1 Answer

up vote 0 down vote accepted

The problem was solved by putting the debug code after the change of values have taken place in the code.

share|improve this answer
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Ajit S Jun 26 at 10:32
Ajit I think the problem was perceptual because the value was probably being added to the array, but since he visually output the array before he added the variable, he perceived that the value was not being added to the array, when in fact it was, and he says as much. – Lester Peabody Jun 26 at 12:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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