I have a couple menu callback entries defined that are called from jquery and thus need to return just an appropriate HTML fragment not an entire page.
The really confusing thing is that one of the menu entries works perfectly (returning help text) but the other one (returning a reference image) returns an entire page with the image.
Here is the code in my module:
function vitalsigns_menu() {
$items['get_popup_help'] = array(
'title' => 'Get popup help',
'access arguments' => array(VSPermissionConstants::AccessContent),
'page callback' => 'vitalsigns_get_popup_help',
'type' => MENU_CALLBACK,
);
$items['get_species_reference_image'] = array(
'title' => 'Get Species Reference Image',
'access arguments' => array(VSPermissionConstants::AccessContent),
'page callback' => 'vitalsigns_get_species_reference_image',
'type' => MENU_CALLBACK,
);
return $items;
}
function vitalsigns_get_popup_help($path1, $path2) {
$full_path = $path1 .'/'. $path2;
$query = "SELECT src FROM {url_alias} WHERE dst='%s'";
$node_path = db_result(db_query($query, $full_path));
if (empty($node_path))
return t("Help topic not found");
$nid = substr($node_path, 5);
$help_node = node_load($nid);
return theme('node', $help_node);
}
function vitalsigns_get_species_reference_image($nid) {
$query = "SELECT ctvss.nid, ctvss.field_species_number_value,ctvss.field_species_illustration_fid, ctvss.field_species_illustration_data, f.filepath ".
"FROM {content_type_vs_species_scientific} ctvss ".
"INNER JOIN {files} f ON ctvss.field_species_illustration_fid=f.fid ".
"WHERE ctvss.nid=%d";
$results = db_query($query, $nid);
while ($record = db_fetch_object($results)) {
$photo_data = unserialize($record->field_species_illustration_data);
return theme('imagecache_imagelink', 'species_illustration', $record->filepath, $photo_data['alt'], $photo_data['title']);
}
return t('No photo available.');
}
In the above code, the call to "get_popup_help" works perfectly. It looks up some help content and returns just the node formatted content without the page wrapper.
The call to "get_species_reference_image" however returns the themed image in the page wrapper.
As far as I can tell, both menu entries are implemented identically so why are they behaving differently?
And how can I make them both only return an HTML fragment rather than a full page?
Comments
Change "return" to "print"
Change "return" to "print" and to be safe add a call to "exit" after the print statement.
Thanks nevets!! That worked
Thanks nevets!!
That worked perfectly. :-)
Thanks,
Shawn
Good evening! Dear nevets,
Good evening!
Dear nevets, thank you very much!
thx nevets, I was having the
thx nevets, I was having the same problem!
Spread the Word
It feels like a hack, but it's what works. Thanks!
Now if we could propagate this information around the documentation and examples.
--
Tom/* Ogden