2

I've programmatically created a new view mode called ajax. Is there any way to force a node page to use that view mode if I'm making an AJAX call? I know how to switch page and node templates when it's an AJAX call in template.php, but it's not quite the same thing.

3
  • As far as I know it's not standard Drupal feature. So, please, explain what do you want to do? What kind of AJAX call are you doing?
    – kalabro
    Commented Jun 12, 2012 at 10:54
  • I'm loading my node page in certain parts of my site into a JQuery popup (i.e., via AJAX), and want a completely different layout when this happens - i.e. not just a different template, but a different view mode (so I can use different fields / field formatters). It might not be a standard feature, but it ought to be possible in my theme. Commented Jun 12, 2012 at 21:04
  • You can do this quckly on Drupal 8/9 like mentioned in my answer here : drupal.stackexchange.com/a/309563/61506 Commented Feb 5, 2022 at 10:54

2 Answers 2

1

If you have a custom handler for your ajax request, I suggest you to manually render the node using node_view api function. It has a view_mode parameter which you should set to 'ajax'.

0

You can make use of Services module

A standardized solution of integrating external applications with Drupal. Service callbacks may be used with multiple interfaces like REST, XMLRPC, JSON, JSON-RPC, SOAP, AMF, etc. This allows a Drupal site to provide web services via multiple interfaces while using the same callback code.

Features(3.x):

  • Service API allow modules to create other services, including pluggable access control
  • Server API allow modules to create other servers, such as SOAP
  • Aliasing methods
  • Integration with core Drupal functionality like files, nodes, taxonomy, users, files and more. ***you can try this option***
  • Response format API allows you to define response Formats for CONTENT-TYPE ie. application/json or application/xml. (also calls such as ENDPOINT/node/1.json work)
1
  • Hmm, no, that's not what I'm looking for. I've used Services before, and I don't believe this is a problem that will solve. Commented Jun 13, 2012 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.