I have 2 almost alike simple views*, where the first one receives a taxonomy term and the second one receives the field Location: City as arguments.

Both of them have Default, Block and Page displays and in both of them the Live preview work like a charm for each of the 3 displays.

In the real use, although, both pages work as their previews and both blocks don't filter the results based on URL given arguments.

*: Using...

  • Drupal 6.20
  • Views 6.x-3.x-dev / Feb-25
  • Better Exposed Filters 6.x-1.x-dev / Feb-25

More informations?


Always here to help.

Comments

dawehner’s picture

Category: bug » support
Priority: Major » Normal
Status: Active » Fixed

In general blocks doesn't see the arguments from url by default. This is how views works.

To be able to use arguments from url in blocks you should use select "provide default argument" and select for example "node: nid from url".

nrdmagnus’s picture

Category: support » bug
Status: Fixed » Active

True. I've worked with all Views versions for D6 and block displays have always been defective in arguments handling.

Now about your suggestion, I'm already using Provide default argument, but together with Taxonomy Term ID from URL option (as the argument is a taxonomy term). The result you've read above.

I've also tried configuring it to Provide default argument combined with the PHP Code option, providing a code snap (pasted ahead) that is already working in the template.php. Again, in Block display Live preview everything worked fine but in the actual block no filtering at all.

So my point with this issue is if Block display is planned to accept arguments:

  1. Live preview should behavior exactly like it's display, showing the same results for any query in the actual block as showed in display preview;
  2. Argument handling basic options in Provide default argument (term ID, node ID, PHP code, etc.) are requisites;

And, please, don't get me wrong here. I do think that Views module is a insanely great piece of work!

 

P.S.: The argument handling PHP code:

$curi = urldecode(request_uri());
$curi = substr($curi, 1, strlen($curi));
$termname = substr($curi, 3, $pos-3); // the first 3 characters don't belong to the argument
$locterm = taxonomy_get_term_by_name($termname);
if (count($locterm) != 0) return $locterm[0]->name;
else {
  $locterm = taxonomy_get_term_by_name(str_replace('-', ' ', $termname));
  if (count($locterm) != 0) return $locterm[0]->name;
  else return '##';
}

dawehner’s picture

If you want to produce much easier(so also code with less bugs) i recommend you to load the node via

$node = menu_get_object();

on a page like "node/123"
or if you are on a "taxonomy/term/123" page

$tid = arg(2);
nrdmagnus’s picture

I think you didn't understand the purpose of this code snippet. Both of your suggestions don't deal with text arguments passed to a view through a path alias (URL).

Anyway the error probably isn't there (as I said before the snippet is working fine in template.php). This was just a test to verify if the problem was with the Taxonomy Term ID from URL option.

In fact both are responding the same way (results and problems) in this case.

nrdmagnus’s picture

Sorry about the wrong PHP code above. It was part of a bigger code and I didn't make the necessary ajustment.

Here goes the working code to get a text argument (representing a taxonomy term) from any URL (node, taxonomy, view, ...) and pass to a view, even on Block display:

$curi = urldecode(request_uri());
$curi = substr($curi, 1, strlen($curi));
// here goes any code to clean the uri
$termname = substr($curi, 3, strlen($curi)-3);
// getting just the relevant argument
$locterm = taxonomy_get_term_by_name($termname);
if (count($locterm) != 0) return $locterm[0]->name;
else {
$locterm = taxonomy_get_term_by_name(str_replace('-', ' ', $termname));
if (count($locterm) != 0) return $locterm[0]->name;
else return '';
}

The view argument can be any text field, but the validation here is handled exclusively by Taxonomy module.

Always here to help.

dawehner’s picture

Category: bug » support
Issue tags: -block in views, -views live preview

That's still not a bug report :)

$curi = urldecode(request_uri());
$curi = substr($curi, 1, strlen($curi));
// here goes any code to clean the uri
$termname = substr($curi, 3, strlen($curi)-3);
// getting just the relevant argument
$locterm = taxonomy_get_term_by_name($termname);
if (count($locterm) != 0) return $locterm[0]->name;
else {
$locterm = taxonomy_get_term_by_name(str_replace('-', ' ', $termname));
if (count($locterm) != 0) return $locterm[0]->name;
else return '';
}

There is a good reason why it's much easier to use $node = menu_get_object() and load the data for yourself.

jaron’s picture

Is there anyway to load a nodequeue machine title as an argument into a block? I can obviously get it into a page display but I can't figure out a way to build that into the php of a block. Any guidance one way or the other would be appreciated.
Thanks.

mustanggb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closing this as outdated, feel free to re-open if you're still looking for a solution and waiting for appropriate assistance.