Using an argument with Insert view

Last modified: September 24, 2006 - 07:55

The [view:myview=maxitem=firstargument] form can be very useful. For example, if you have a site with the following structure (every node except Home is a book page) :

  • Home
    • Transport
      • Cars
      • Taxi
      • Train
      • Airplane
      • Web sites
    • Culture
      • Museum
      • Library
      • Theatre
      • Web sites

Web sites nodes may seem redundant but they only show web sites about transport or culture. If you had no argument, you should create a view for each one (for example view_culture_sites and view_transport_sites).

One might say you wouldn't need the Insert view module as the Views module already allows you to create a page view with argument. That's true, but you won't be able to attach it to the book structure.

In the example, you need a node that can store URLs (either a new CCK node or a Jan's node, or whatever you want) and a taxonomy attached to it.

You then create your view with the Views module and define an argument on Taxonomy Term ID (or Taxonomy Term name).

In every Web sites node you insert the following tags :

  • [view:websites=100=transport] for the transport web sites page,
  • [view:websites=100=culture] for the culture web sites page.

Multiple Terms in an Argument

Matthew Davidson - September 28, 2006 - 01:21

Here's a Q&D hack to permit multiple taxonomy terms in each argument by escaping commas with either backslashes or URL encoding (eg. [view:websites=100=transport\,culture] or [view:websites=100=transport%2Cculture]):

<code>--- insert_view.module.old      2006-07-07 02:00:36.000000000 +0000
+++ insert_view.module  2006-09-28 01:03:35.000000000 +0000
@@ -72,7 +72,10 @@
          $replace = "";

          if ($view_args != NULL) {
+           $view_args = str_replace('\,','%2C',$view_args);
            $view_args = explode(',', $view_args);
+           for ($i=0;$i < count($view_args);$i++)
+            { $view_args[$i] = str_replace('%2C',',',$view_args[$i]); }
          }
          else {
            $view_args = array();

Using multi-word arguments

tortoise - May 11, 2008 - 05:18

One thing about the arguments in Insert Views that took me a while to realize is that multi-word arguments should be entered with spaces. Since I had only previously invoked Views arguments via URL, I assumed that they would have '+' as a separator. For instance, I created an external_links view that accepted a taxonomy term as an argument. If I wanted to do a page view of the links classified as 'music blogs', I would point my browser at mysite/external_links/music+blogs but inserting [view:external_links==music+blogs] came up empty. I first decided that maybe multi-word arguments were broken, edited my vocabulary to use single-word terms, and inserted [view:external_links==blogs] to get the desired behavior. Only then did I go back and try [view:external_links==music blogs] and have it work.

Steps to do this in Drupal 6 please

saurabh.bhambry - October 13, 2009 - 20:25

The documentation here seems to be dated. Please give the instructions to use arguments passed in the URL for the page display of the Views 2 using Insert View.

Bhambry

 
 

Drupal is a registered trademark of Dries Buytaert.