0

Can someone please tell me if this is possible? I have 2 content types, with the following fields.

  • Asset

    • Title
    • Serial Number
    • Model
  • Event

    • Title
    • Event Type (taxonomy)
    • Asset ID (a plain text field used to store links to Asset nodes)

Is there a way in views 3 to create a view that looks like Asset Title : Asset Serial Number : Asset Model : Event Type, basically a view linking both content types on one line. I've heard you need to use relationships, but I can't seem to get anything working.

0

You need to create an event view with the asset ID as relationship. Then, add the field Asset serial number and select the right relationship, which should be below or above the Label setting.

I don't think this is the best option. It could be really performance consuming. First you need to create an event field view with event type and asset ID (the asset ID should be excluded from display). Go into the view folder, open theme, copy the views-view-unformatted.tpl.php file and paste it into you theme folder with the other template files (sites/all/theme/YOURTHEME/template). In the third column, click on theme and look for the style output (views-view-unformatted.tpl.php). There will be many of this. Use the more specific for that view (usually the last one), something like views-view-unformatted--event--page_1.tpl.php.
Rename the file you copied in your template. Create an asset field view with the serial number and the node ID as contextual filters.

This is how a views-view-unformatted.tpl.php file looks like.

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div class="<?php print $classes_array[$id]; ?>">
    <?php print $row; ?>
  </div>
<?php endforeach; ?>

You should modify it in this way

    <?php if (!empty($title)): ?>
      <h3><?php print $title; ?></h3>
    <?php endif; ?>
    <?php foreach ($rows as $id => $row): ?>
      <div class="<?php print $classes_array[$id]; ?>">

        <?php print $row; 
print views_embed_view('ASSET_VIEW', 'page_', $view->result[$id]->YOUR_FIELD);
?>
      </div>
    <?php endforeach; ?>

Test it.

print views_embed_view('ASSET_VIEW', 'page_', $view->result[$id]->YOUR_FIELD); will print the asset view. $view->result[$id]->YOUR_FIELD will print the asset ID from the event view.

  • Thanks for the response, however I'm not sure what you mean by 'select the right relationsip'. All I see is Create Label , Label, Place a colon after label, Exclude from display, Formatter? – Brian Aug 22 '12 at 13:53
  • Is the ID Asset field a node reference type? – Tyler Durden Aug 22 '12 at 14:26
  • Nope plain text and I don't think I can convert it now that the content is in, right? – Brian Aug 22 '12 at 14:31
  • I'm not sure you can convert it from text to node reference. Probably you should create a new one. – Tyler Durden Aug 22 '12 at 15:10
  • Yeah that's not really an option with 50,000 nodes unless there is a way to automatically move the data from the text field to the node reference field. – Brian Aug 22 '12 at 15:24
1

A better way to do it is replacing the asset ID field with an entity reference field which refers to the other content type (Asset) and use view relations to get the relation. In short, create a relation between the content types, and you will be able to use view relations.

For advanced uses, you can take a look to the Relation module, which I don't recommend, in your case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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