hey all,

I wanted to have a dedicated template for the output of a reference preview. So I add a preprocess_node hook in the module, to load a new template for my content type, only in the specific case of outputing a preview. It works fine so far.

Just add this function on top of the reference_preview.module file:

function reference_preview_preprocess_node(&$vars){
  
  // Test if we are on a ahah page 
  $is_ahah_page=strstr(request_uri(), 'reference_preview_ahah');
  
  // Add a template_files only for ahah page
  if($is_ahah_page){
    $vars['template_files'][] = "node-".$vars['type'].'_reference-preview';  
  }
}

Then one has to create in the folder
/path_to_your_theme/templates/node/
the file
node-yourcontenttypename_reference-preview.tpl.php
and the preview is displayed according to this tempalte file.

What do you think about it ?
For me it works fine. I think it could be a nice feature for the module.

Liaz.

Comments

hefox’s picture

Good idea

Looking at the repo, it looks like $node->reference_preview_field_settings is defined with the settings, so I'd be totally cool with a patch that adds template suggestions like:

if (!empty($vars['node']->reference_preview_field_settings)) {
  $vars['template_files'][] =  'node-reference-preview';
  $vars['template_files'][] =  "node-" . $vars['type'] . '-reference-preview';
  $vars['template_files'][] =  "node-" . $vars['type'] . '-reference-preview-' . str_replace('_', '-', $vars['node']->reference_preview_field_settings['field_name']);
}

Provide a patch (follow coding standards, see d.o page on how to create patches, etc.), and I'll review it :).

Liaz’s picture

Great !

I will do that in a week.
Should I add also the changes I talked about there : http://drupal.org/node/1629992 ?

Liaz’s picture

Another nice feature I was thinking about would be to possibly to customize where you want to display the preview regarding the nodereference field. Now it is after, but I figured out that in the .js it is just a small change to do

        $(this).before(content);

instead of

        $(this).after(content);

I found how to display this option in the .module

$position_options = array(
        'before' => 'before',
        'after' => 'after',
      );
$settings['reference_preview']['position'] = array(
        '#type' => 'select',
        '#title' => t('Reference Preview Position'),
        '#default_value' => !empty($field['reference_preview']['position']) ? $field['reference_preview']['position'] : 'before',
        '#options' => $position_options,
      );

But I don't know how to use it in the .js then.

If you could give me an advice I could try to add this feature also in the patch.

hefox’s picture

Any patches/issues I'll consider, however one issue per feature/bug report please, and patches should just include the chance for that issue.

Additional configuration for placement sounds fine.