I want to create a theme that inherits Clean and also use nice_menus for my primary links. There is no navigation region to assign the nice menu primary links block to, so I want to go down the route of using my template.php to preprocess $primary_links to call theme('nice_menus_primary_links'). This would all be fine, but clean_preprocess_page() still gets called.
The code in question is
<?php
$variables['primary_links'] = (!empty($variables['primary_links'])) ?
theme('links', $variables['primary_links'], array('class' => 'links primary-links')) :
$add_link;
?>
First of all, $add_link is not defined anywhere. Second I think instead of !empty this should check is_array().
New code:
<?php
if (is_array($variables['primary_links'])) {
$variables['primary_links'] = theme('links', $variables['primary_links'], array('class' => 'links primary-links'));
}
?>
Thoughts?
Comments
Comment #1
soulston commentedHi,
I made a patch file for the above issue. I think you are correct to use !empty instead of is_array.
I merely removed the $add_link variable and set it to ''.
Comment #2
mstrelan commentedThe reason I chose to use is_array was because MYTHEME_preprocess_page() rendered an array as a string, so when it gets to clean_preprocess_page() my string was getting overridden. This way clean can only render primary_links if it hasn't already been rendered
Comment #3
psynaptic commentedPrimary links is a string by the time it gets to your theme's preprocess_page, is that what you are getting at?
Comment #4
mstrelan commentedyeah... i couldn't remember exactly what happens so i think my previous post is a bit erroneous ... nonetheless the code in the original question works
Comment #5
soulston commentedHi,
I am including another patch that assigns the primary links array to $variables[primary_links_themed] which is then output in the page.tpl.php file. This means you can still have access to the primary_links and secondary_links arrays and is maybe more in line with the move to D7.
Comment #6
mstrelan commentedOk I've started a new project based on clean and came across this issue again so I can hopefully describe it better now.
clean_prepreprocess_page() is executed AFTER mysubtheme_preprocess_page(). The latter of the two renders the primary links as HTML, and therefore the former re-renders the HTML, completely overriding the work done in the subtheme.
It seems to me that this is a bug in Drupal core, as I would have expected the subtheme to have the final say, otherwise it is not really a subtheme. I'm trying to determine if #328122: Kill base theme's hook_preprocess_page function is related but couldn't be bothered to read it thoroughly.
Comment #7
Cyberflyer commentedAm adding a note here for the benefit of anyone with my situation who may follow.
I developed a sub-theme of clean 960gs , based on Clean 1.2. When I transitioned from PHP 5.2.17 to PHP 5.3.10 to prepare for a server host upgrade, I found problems with clean, so I installed Clean 6.x-2.0-beta3, which solved them.
And the Primary Menu disappeared on all my pages! Instead of a link menu bar, I got 'array array" in text.
In the page.tpl.php and other content type.tpl.php code the variable names changed from:
to:
Changing the code on my tpl.php pages brought the menu back. Same issue is likely there for site_name, etc, although I am not using them in my theme.
Comment #8
psynaptic commented#6: I can't reproduce the issue with preprocess_page from Clean firing after preprocess_page from a sub theme.
#7: I have removed the _themed versions of variables now. That turned out to be too confusing and just a bad idea in general.