OP sub-theming difficulty: adding variable for use in node-article.tpl.php

Events happening in the community are now at Drupal community events on www.drupal.org.
crotown's picture

Dear fellow OpenPublish folks,

I am using OP 2.2 and am having difficulty providing my own preprocessor variable to be used in a custom version of node-article.tpl.php that is in a sub-theme of openpublish_theme.

What I would like to do is override openpublish_node_article_preprocess() but the site seems to look for it in openpublish_core/theme_helpers/node-article.tpl.inc. I am trying to understand openpublish_core/theme_helpers/router.inc and its function openpublish_core_suggest_preprocessor() to see how I might inject my own variable without hacking, but I would appreciate some help from someone who has gone this road before (or designed OpenPublish).

Adding your own preprocessor variables is an important part of (sub-)theming. It clearly need some documentation, and I'd be happy to write some up for the community. But some help doing it at all mat be necessary, first.

Also note that a similar question was asked several weeks ago at http://groups.drupal.org/node/78603#comment-307789 and has not yet been answered.

-Steve Cronen-Townsend

Comments

Are you trying to alter the

irakli's picture

Are you trying to alter the variable in template.php or in your custom module?

thx

.............................................
http://twitter.com/inadarei

Here's what I am doing

crotown's picture

I am creating a slideshow of featured articles (well) like the one on the frontpage of tnr.com.

From looking at tnr.com's markup I chose to use the views_slideshow module. My WellSlidehow view has Style:slideshow and has Row style:node. The row has Build mode:well. The reason I chose row style node is that the markup seemed to match tnr.com's better than when using row-style field. (I needed to implement the CCK hook_content_build_modes() to define the custom build mode well.) My plan is to co-opt the teaser build mode to just output Title an Author links to do the breakout nodes just as on tnr.com, but I have not tackled this aspect of the problem yet.

So, what I think I want is to have $node->build_mode for the Article node present as $build_mode when the node is printed in node-article.tpl.php. In my override of that template I want to use the custom $build_mode value of 'well' to mean the node should be printed as just the well-version of the main image. Then, with the Thumbnail Hover plugin's option Hover Breakout set to Teaser I think I will be all set to markup for the nodes in the slideshow to appear to the right of the slideshow as Title and Author links as on tnr.com.

So, I'm thinking that any way of getting $build_mode available in the article template is what I want. I've made some attempts at both ways, of having in the sub-theme's template.php and putting code in a custom module. I do not have a strong preference, except for the overall result (and having the solution upgradeable).

Perhaps I'm not going about this the easiest way, and I'd love to know that, too. Thanks for any advice.

I apologise for sidetracking.

kenyan's picture

I apologise for sidetracking. Anyone else wanting to do what you are doing should maybe try DDBlock https://drupal.org/project/ddblock.
The preprocess functions to set it up go into the themes template.php file in DDBlocks case and are available from project site.

Thanks for the reply, reluctant to install another module

crotown's picture

@kenyan Thanks for the reply, but I am reluctant to install another module and take a different approach when I just want have a capability that is part of being able to theme generally in Drupal. And if I use an additional module but don't get the underlying OP sub-theming question answered I am not going to be able to theme custom fields I have added to Article, without hacking things.

I understand why there is a "firewall" between the full node and things that are accessible when the node is displayed. But I should be able, somehow, to marshall whatever information I want to display across this "firewall". Drupal has a standard way of doing this with preprocess functions. This standard approach does not work for me for sub-themes of openpublish_theme, and the knowledge about how to get it to work should not be hard to obtain if anyone is going to be expected to make sub-themes of openpublish_theme.

@irakli Can you please clear this up? Thanks.

@crotown: following is the

tirdadc's picture

@crotown: following is the code I tried. Is it similar to what you attempted earlier on in template.php? I created a subtheme, then defined a template_preprocess_node() function in its template.php. This way all the preprocessing by OP stays intact and you can do any additional stuff you want right after that:

<?php
function sub_theme_preprocess_node(&$vars) {
  if (
$vars['node']->type == 'article') {
   
// Put your logic here and define your additional node-article.tpl.php variables and then
    // create your own node-article.tpl.php in your subtheme that has $buildmode
    // (don't forget to copy node.tpl.php into your subtheme too)
   
$vars['buildmode'] = 'well';
  }
}
?>

This code worked in our test. Please let us know if yours is different.

Thanks

Thank you -- my error

crotown's picture

@tiradc Thanks for your reply. Your code works for me -- and on retrying it, my the code I was trying in template.php worked, too. It turns out that I had been checking for the routine being run by setting a breakpoint in Eclipse. But there are two ways to get to the same file in Eclipse's "PHP Explorer", and I was opening the file in the way that breakpoints appear to be set but are never hit. When I set the my breakpoints properly in Eclipse correctlky I found that my existing code was being called. So it was my mistake (and a tiny bit the tool's).

We really need the documentation (i.e. at http://openpublishapp.com/doc/customizing-base-theme-sub-theme) to be finished, since having some code published showing how inserting a variable into a template for the openpubish_theme would have helped me catch my error myself and prevented my false alarm. I would like to volunteer to complete the theming documentation. Please advise me as to how to get involved.

Again thanks, and sorry!
Steve Cronen-Townsend

Similar issue

dale386's picture

I am having a problem overriding the openpublish_preprocess_page() function. My code in sub_theme_preprocess_page() seems to be ignored by Drupal. (Yes, I am using my theme's name in place of "sub_theme"!).

Any suggestions?

Thanks

Thanks, Steve. We are working

irakli's picture

Thanks, Steve. We are working on making docs better.

Glad to hear the problem was resolved.

.............................................
http://twitter.com/inadarei

OpenPublish

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: