When trying to add a page region to a node template, I found that Context did fill in that region, but failed to fill in any external regions in the page template. This is either because:

1) the 'sitewide' condition fails to fire or
2) the regions are unable to retrieve the necessary blocks

The Context Inspector block shows the sitewide context as active -- it simply isn't causing blocks to appear. Therefore, I'm leaning towards explanation 2.

Comments

katherined’s picture

I have the same problem. I am using Context 6.x-2.0 though, but almost the same exact thing is going on. In my case it is the default condition (I think this is only an option in the 2.0 version right now) that fails when theme('blocks', 'regionname') is called. Sitewide and other conditions work, but I need the default condition.

I also need the block region in node.tpl.php. Wondering if there's a workaround?

add1sun’s picture

This is because Context is doing a hook_theme_registry_alter to control blocks. In that hook in context.core.inc, there is a comment that basically you have to deal with it on your own:

  // Reroute theme_blocks() through context_blocks to determine block
  // visibility by context. Only override theme_blocks() if a theme
  // has not overridden it. It is the responsibility of any themes
  // implementing theme_blocks() to take advantage of context block
  // visibility on their own.

So basically you need to pull some of Context's code into your theme. Once I figure out exactly what needs to be done I'll post back. We should also get this documented somewhere that people would actually find it, especially if they aren't the type who can dig into the module code to find out what the real problem is.

yhahn’s picture

Title: Context fails to fill in page regions when theme('blocks', 'REGIONNAME') is called in template_preprocess_node » Blocks: theme('blocks', 'REGIONNAME') fails when called in template_preprocess_node
Version: 6.x-3.0-beta4 » 6.x-3.x-dev
Assigned: Unassigned » yhahn
Priority: Normal » Critical

This occurs because theme('node') is often called too early in the page generation stack for all context conditions to have run.

I'm not sure I'll be able to address this problem but it's on my list.

njbooher’s picture

Title: Blocks: theme('blocks', 'REGIONNAME') fails when called in template_preprocess_node » Context fails to fill in page regions when theme('blocks', 'REGIONNAME') is called in template_preprocess_node
Version: 6.x-3.x-dev » 6.x-3.0-beta4
Assigned: yhahn » Unassigned
Priority: Critical » Normal

I too encountered this (3.x-dev), however, from context inspector it looks like the sitewide context isn't active after calling theme('blocks', 'REGIONNAME') from template_preprocess_node while my node-type conditioned context is. Removing the call to theme('blocks', 'REGIONNAME') from template_preprocess_node makes them both active.

yhahn’s picture

Title: Context fails to fill in page regions when theme('blocks', 'REGIONNAME') is called in template_preprocess_node » Blocks: theme('blocks', 'REGIONNAME') fails when called in template_preprocess_node
Version: 6.x-3.0-beta4 » 6.x-3.x-dev
Assigned: Unassigned » yhahn
Priority: Normal » Critical

Assuming you didn't mean to blow away these changes : )

yhahn’s picture

Status: Active » Fixed

This should be fixed with http://drupal.org/cvs?commit=399958.

Note that some conditions fire too late (sitewide condition, menu trail condition in particular) to be used in conjunction with a context that provides blocks in a node template region. Other conditions, like the node type or path conditions, should work.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dsayswhat’s picture

Version: 6.x-3.x-dev » 6.x-3.0
Status: Closed (fixed) » Needs work

Hi there -

I'm using the context 3.0 release, which should incorporate the patch above, no? Your notes mentioned that '...Other conditions, like the node type or path conditions, should work...'

My context uses a node type condition, places a block, and works normally in the typical use-case. However, I'm encountering the same issue as described above.

However, preprocess_node is unable to pull the content in using theme('blocks', 'region') or context_blocks('region').

In fact, doing so wipes out the context. I've echoed the region it in the page.tpl.php file to doublecheck things, as well as attempting to include it in my node.tpl.php...and it blanks the content of that region out when the preprocess_node function touches theme('blocks') or context_blocks(). Commenting the line makes it work again.

After dumping variables at a variety of places, it appears my template_preprocess_node is getting called BEFORE context runs - that's probably normal, but under the conditions you describe, I thought a note-type condition might work. Seems it doesn't.

In the short term ( deadlines loom, after all ), what tips can you offer about the comment reading :

  // It is the responsibility of any themes
  // implementing theme_blocks() to take advantage of context block
  // visibility on their own.

I tried to use various pieces of context in my preprocess function without success - calling in context_blocks, and some of the bits that it calls. However, I was unsuccessful, and I'm at a loss as how to proceed...so how would you recommend I take advantage of context block visibility?

Are there any ways to work around this, or any way I can help troubleshoot, further info I can provide?

Thanks for the great module...and for supporting all our edge cases.

bleen’s picture

Re #6: Based on our recent experience on a project, I'm assuming that "context" conditions also fire off too late for this to work properly. Can anyone confirm this? In our case the context condition referred to a context that only uses "path" as a condition.

vasike’s picture

subscribe

breathingrock’s picture

We found our solution by stripping the context condition (or condition of type context) out of the contexts altogether. Then adding this bit of code to work that condition by hand so to speak:

/**
* Preprocessor for nodes.
*/
function [module_name]_preprocess_node(&$vars) {

if (context_get('context', 'alpha')) {
context_set('context', 'beta', new stdClass());
}
else {
context_set('context', 'gamma', new stdClass());
}

}

So we're essentially making the 'beta' and 'gamma' contexts active in the same places, then checking to see if the 'alpha' context is active to decide which one should be DEactivated. Kind of doing things in reverse. Make sure to deactivate the contexts by setting them to new stdClass() or you'll get PHP errors of the "can't access property from non-object" variety. You could probably use context_del('context', 'xxx'); but be sure to test thoroughly there.

Hope that makes sense. ;)

jorditr’s picture

Hi add1sun, I'm just asking that on another thread. Did you find the way to do it?

planctus’s picture

Is this an issue also in Drupal 7..?
Because it seems i cannot get the region in a node to be filled with blocks basing on a context.
Thanks,
Da.

  • yhahn committed b54eba7 on 8.x-4.x
    #759554: Allow theme regions to be rendered in node template for a...

  • yhahn committed b54eba7 on 8.x-0.x
    #759554: Allow theme regions to be rendered in node template for a...

  • yhahn committed b54eba7 on 8.x-1.x
    #759554: Allow theme regions to be rendered in node template for a...
deaom’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)