I have a view with 1 page display and 1 attachment display.

The attachment uses the sole argument: "Global:Null" overriding the default.

If the argument returns true, I'd like the attachment to show. Otherwise, I'd like it not to show.

Here's what I've done:

In the argument form, I left the title and breadcrumb fields empty.
I checked "Action to take if argument is not present: Provide default argument"
"Default argument type:PHP Code"
"Validator: PHP Code"

I notice there's a text field with no label above the textarea where I entered the php.
Do I need to enter something in this field?

I've tried the following various arguments, all which should return a boolean value, but the attachment won't show on the view.

if (empty($_GET['page'])) {
return true;
}else{
return false;
}

and this...

$showattachment = getenv("REQUEST_URI");
if (!strpos($showattachment, "page=")){
return true;
}
return false;

and:

$showattachment = getenv("REQUEST_URI");
return (preg_match("page=",$showattachment));;

I just want the attachment (five special results) to show on the first page of the results, but not on subsequent pages (?page=1,?page=2, etc.).

What am I missing here?

Comments

boblangdon’s picture

Fixed.
I found a good solution was to add this right to my "views-view.tpl.php" template:

<?php
if (($attachment_before) && (empty($_GET['page']))): ?>
    <div class="attachment attachment-before">
      <?php print $attachment_before; ?>
    </div>
  <?php endif; ?>

Although I still don't understand views arguments syntax.
8^/

esmerel’s picture

Status: Active » Closed (fixed)

Poster solved own issue.

sagesolutions’s picture

Issue summary: View changes

For Drupal 8.2

You can make a module with the following

<?php
/**
 * Hides attachment on taxonomy listing pages. Attachment is used to show featured items, but we only want to display 
 * the featured items on the main page, not on all pages. 
 */
function mymodule_views_pre_render(\Drupal\views\ViewExecutable $view) {
    if ($view->id() == "taxonomy_term" && $view->current_display == 'page_1') {
	    if ($view->getCurrentPage() > 0) {
	    	$view->attachment_before = array();
  		}
    }
}