Posted by NoCoolNamesRemain on August 31, 2009 at 5:03pm
Jump to:
| Project: | Insert Block |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
I would like to be able to pass arguments to the block being called. It seems similar functionality is built into the Insert Views module and it also seems to be supported by module_invoke(). The biggest challenge for me would be correctly modifying the regex used by this module (_insert_block_substitute_tags()).
Comments
#1
Here is what I have come up with (which is working for me). I would like someone to verify that the regular expresion does ONLY what I want.
function _insert_block_substitute_tags($text) {
if (preg_match_all("/\[block:([^=\\]]+)=?([^=\\]]*)? args:?([^\\]]*)?\]/i", $text, $match)) {
foreach ($match[3] as $key => $value) {
$raw_tags[] = $match[0][$key];
$module = $match[1][$key];
$delta = $match[2][$key];
$args = $match[3][$key];
if ($args != NULL) {
$args = explode(',', $args);
}
else {
$args = array();
}
$block = module_invoke($module, 'block', 'view', $delta, $args);
$repl[] = theme('insert_block_block', $block);
}
return str_replace($raw_tags, $repl, $text);
//return print_r($match); //TESTING
}
return $text;
}
[block:MODULE=DELTA args:ARG1,ARG2,...,ARGN]#2
I just encountered a similar hurtle when creating a view displaying as a block, and the block needed a argument. The view needs has a argument for Node Hierarchy: Parent Node ID. I've exported my view and put it up as an example. I had to specify the default parent ID, but it would be ideal to have the parent id passed to through. Is this possible?
#view export
http://snipt.org/wnmt.
#3
Try NoCoolNamesRemain's substitute code and post back here whether or not it works for you. That would help the maintainer know if it works.
#4
with a little more research on this, I solved my problem. Not 100 percent related to this topic since I didn't use this code, but for what it's worth I just needed to do a views argument with "Node ID from URL" to pass the parent node id to the view.