From a lot of things I've been reading, it seems Views could accomplish the following, and that might even be the preferred way of going about this? Anyway, after trying hard for a long time I don't seem able to get this happening without some help -
I have a list of links to Audio nodes being generated by Apache Solr Search Integration. On click, any of these links needs to display the Audio node it links to in a right column block without a page refresh.
I have altered search-result.tpl.php, giving the above-mentioned links to Audio nodes an Ajax class and altering their path so they become links to a View I have created which takes a default argument type of PHP Code:
$nid = arg(2);
Testing those altered links, the View is using Ajax successfully as a page display if I manually insert valid node ids as the 3rd argument in the URL via the browser address bar. I created a block display of this View but I can't figure out how to ID the block or how to write proper Drupal javascript to load the view in the block.
I tried adding a div around the $right var in my page.tpl.php and giving it an id. That doesn't seem to be working. Is there some way to target a Views block with an ID so I can tell Javascript where to put the View? Or should I even be trying to use the Views block display rather than a regular block?
I added this script I found to my script.js, and have been trying to figure out if I can alter it for this purpose. But no dice, despite the fact I know the href attribute it is getting is viable:
/** beginning of file **/
if (Drupal.jsEnabled) {
$(document).ready(function () {
$('a.AjaxMe').click(function(){
var AjaxSRC = $(this).attr('href');
$('#AjaxTarget').empty().load(AjaxSRC + '#AjaxMe');
return false;
});
});
}
The above script actually works after a fashion to just load nodes in a right column block, but it loads all regions of a whole new page into the target div (displaying a page within a page). It also only displays a single field of the node (none of the default fields).
I've been at this for weeks... any help would be very greatly appreciated, especially if anyone could explain exactly (as opposed to generally) what I would need to learn to figure this out myself.
Thanks very much for any input.
Comments
Comment #1
butler commentedRemoved...
Comment #2
dawehnerA bump after one day is considered to be a bad behaviour. Please look at the issue queue and the amount of issues coming in every day. You just waited 24h + 2min
What does this page returns? Can you show us this code?
Comment #3
butler commentedEDIT 20110519 - changed code below to reflect current state of this wannabe module... please note I have junked the entire approach above in favor of creating a module after finding this excellent seeming tutorial by zzadik:
http://viziontech.co.il/node/6
... and I think I have it almost working - there's definitely something still wrong - nothing now happens on clicking the links. I am pretty sure that my callback function is not getting a node id, or is broken in some other way that I can't understand so far - this is my first time doing anything asynchronous so it is probably something dumb.
dynamic_audio_node.module
dynamic_audio_node.js
An Export Of most_recent_audio_node_view - The View I'm Trying To Embed -
It would be great if I could get something like this working and contribute-able... there are so many people out there trying to figure this out and it seems like such a common thing to need to do. Thanks anyone.
Comment #4
dawehnerAre you sure this.href has the right url?
If you know this you could jump into dynamic_audio_node_get_by_node_id and look whether it has the right $nid.
But there is another problem in your code
Views_embed_view does not expect an array of arguments. You should use it more like this
Hopefully this fixes your problem
Comment #5
butler commentedThanks so much dereine. There was a comment on the tutorial re: not passing an array to views_embed_view() which I had forgotten about. Unfortunately this is still not working but that needed fixing anyway. I now have:
Now trying to try to figure out how I can test this.href - the links as rendered look like I think they should look:
/?q=r_col_audio_node/226
... so trying to figure out if that is somehow being mangled or I'm misunderstanding how to use hook_menu().
Anyway thanks much again.
Comment #7
butler commentedStill getting nowhere. Via javascript alerts I was able to determine that this.href is correct... but still can't figure out how to debug the php callback function.
Tried putting this at bottom of my node.tpl.php:
... and, though the page loads, var_dump() shows nothing at all - as though there were no defined vars for the page... I can only imagine that this means something like that there are no defined vars for the document in its current state. Maybe meaning that $nid is not getting a value and that that breaks the page in some state where there are no vars?
Anyone got any idea or direction to suggest re: how I can figure out what's going on? It seems like this is so close to working but... ???
Comment #8
dawehner$nid is probably not availible on the node.tpl.php
You could use $node->nid instead.
Instead of writing stuff directly to the node.tpl.php it is better to add a new variable via hook_preprocess_node.
Comment #9
butler commentedThanks for the new reply dereine... I am becoming convinced my problem lies within this function, or perhaps the View, although it seems to work fine on its own. I tried just setting $nid here like:
... and it broke the entire site (blank/white screen on refreshing any page)! Tried setting a variable with arg[1] and replacing $nid with that (blank/white screen on refreshing any page), tried replacing $nid with arg[1] in views_embed_view() instead, result: back to no action on click.
The url of this.href is definitely there as arg[1]. Anyone have any idea why trying to set a variable with this should cause my module to hang the whole site? Am I not understanding, in terms of scope, how/where arg[1] is available?
Comment #10
dawehnerHow are $viewName, $displayId defined? Probably yes but take sure again.
Such things are hard to solve without any kind of local reproducablability.
Comment #11
butler commented$viewName, $displayId are just set statically here (here's the whole callback function):
Comment #12
butler commentedWondering if this could have to do with the initial page being a page of search results via Apache SOLR Search Integration and Apache SOLR Facetbuilder. There is a fair amount of Ajax going on on this page without this... autocomplete, etc. Also Apache SOLR Facetbuilder uses Views to define facets, so loading this other Audio Node View - could all this be competing somehow... ?
Again, any replies or insights greatly appreciated.
Comment #13
esmerel commentedComment #14
kars-t commentedHi
I am closing this issue to clean up the issue queue. Feel free to reopen the issue if there is new information and the problem still resides. If not please make sure you close your issues that you don't need any more.
Maybe you can get support from the local user group. Please take a look at this list at groups.drupal.org.