Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've done this before on D6 where basically I just create a couple template tpl.php files for my View-1.</p> <p>Inside my View-1 template for Display Output (views-view--default.tpl.php in D7 now) I would simply programmatically find the value passed or returned by View-1 for this row.</p> <p>In your case on each row you would check to see which node is returned by View-1 and then I'd add code in my View-1 template to programmatically load View-2 based on the current View-1 row (ie. node in your case.)</p> <p>Make sense? 5 months late on the response but I was looking for a refresher and seeing if there's a better way to do this now in D7.</p> <p><strong>UPDATE</strong>:<br/>Just did this on my new D7 install. As an example I'll explain how it relates to my Ubercart implementation.</p> <p>Ubercart, when installed, has it's main "home" shop page located at <code>mysite.com/catalog</code></p> <p>This page, when loaded, calls a View created by Ubercart called <code>uc_catalog_terms</code>. It is a taxonomy based view and all it does is grab all your Catalog taxonomy categories and render them.</p> <p>E.g </p> <p>As a clothing store, when you navigate to <code>mysite.com/catalog</code>, all you'll see at this page is a grid structure like:</p> <p>Sweaters Shirts Jeans </p> <p>My requirement was that I needed to show the shop catalog categories/terms on this page, but <em>ALSO</em> show 3 random products (images) from that category/term below it each catalog category.</p> <p>E.g</p> <p>Sweaters<br> Random Sweater #1 - Random Sweater #2 - Random Sweater #3<br></p> <p>Jeans<br> Random Jean #1 - Random Jean #2 - Random Jean #3</p> <p>How is this accomplished?</p> <p>I created my own brand new custom view (no page or lock, just default) which grabs 3 random product images based on a <em>taxonomy term ID argument</em> and renders 3 linked product images. I'll call this custom view <code>random_catalog_items</code>. If <code>15</code> is the term ID for Sweaters, when this view is called with the argument <code>15</code> it will only render 3 random linked sweater product images.</p> <p>I now went back to <code>uc_catalog_terms</code> view and created a <code>views-view-fields--uc-catalog-terms.tpl.php</code> (Row Style Output) template file.</p> <p>THE DEFAULT VIEW VERSION OF THIS FILE (BEFORE MODIFICATION) IS:</p> <pre><code>&lt;?php foreach ($fields as $id =&gt; $field): ?&gt; &lt;?php if (!empty($field-&gt;separator)): ?&gt; &lt;?php print $field-&gt;separator; ?&gt; &lt;?php endif; ?&gt; &lt;?php print $field-&gt;wrapper_prefix; ?&gt; &lt;?php print $field-&gt;label_html; ?&gt; &lt;?php print $field-&gt;content; ?&gt; &lt;?php print $field-&gt;wrapper_suffix; ?&gt; &lt;?php endforeach; ?&gt; </code></pre> <p>THE MODIFIED VERSION BECOMES:</p> <pre><code>&lt;?php foreach ($fields as $id =&gt; $field): ?&gt; &lt;?php if (!empty($field-&gt;separator)): ?&gt; &lt;?php print $field-&gt;separator; ?&gt; &lt;?php endif; ?&gt; &lt;?php print $field-&gt;wrapper_prefix; ?&gt; &lt;?php print $field-&gt;label_html; ?&gt; &lt;?php $title = str_replace('/','-',strtolower($field-&gt;raw)); print '&lt;img src="'.drupal_get_path('theme','my_theme').'/images/catalog/'.$title.'-header.png" /&gt;'; print '&lt;hr style="width: 100%; background: #000; height: 2px; margin-top: 3px;"/&gt;'; // get the taxonomy term ID $tid = $row-&gt;tid; // render the 3 random items if ($random_products = views_get_view('random_catalog_items' )) { print $random_products-&gt;execute_display('default', array($tid)); } ?&gt; &lt;?php print $field-&gt;wrapper_suffix; ?&gt; &lt;?php endforeach; ?&gt; </code></pre> <p>So as you can see inside the first View, for every row that is rendered I get the current taxonomy term ID being shown through the available row result object - <code>$row-&gt;tid</code> and then I simply call my created view for each row, passing along this Term ID as the argument for it. I leave a lot of the default code in there but inside my view configurations the LABELS and such are set to <em>HIDDEN</em> so they don't even render anyway.</p> <p>In your case it should be very easily adaptable to just pass a Node NID instead of a Taxonomy Term ID.</p> <p>VOILA IT ALL WORKS! View within a View! Hope this helps :)</p> <p>It helps to have the Devel module loaded since then inside these View templates you can debug and see what variables are available to you via something like <code>print krumo($row)</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload