By jriddiough@gmail.com on
Hi,
I'm building a tool that is meant to generate a json file for the user to download. The download link is displayed on the node page.
Here is the live example: https://boycottplus.org/campaign/new-hope
I want to take the node data and output as a json file, maybe https://boycottplus.org/campaign/new-hope.json
I've looked into node views and have a node view module for creating a json view. Now I don't know how I could tell drupal to look for the .json extension and then to produce the correct version of the node view.
function jsonview_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['jsonview'] = array(
'label' => t('json View'),
'custom settings' => TRUE,
);
}
function jsonview_preprocess_node(&$vars) {
if($vars['view_mode'] == 'jsonview') {
$vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__json';
}
}
Comments
the alternative for me is
the alternative for me is running a shell script when the node is saved to render the json and attach it to the node.