diff --git a/core/lib/Drupal/Core/Template/TwigTemplate.php b/core/lib/Drupal/Core/Template/TwigTemplate.php
index 7d7eeca..ba71eeb 100644
--- a/core/lib/Drupal/Core/Template/TwigTemplate.php
+++ b/core/lib/Drupal/Core/Template/TwigTemplate.php
@@ -51,6 +51,13 @@
       return NULL;
     }
 
+    // Turn off references for looped items
+    // @todo hide, show is not supported for them for now.
+    // @see http://drupal.org/node/1867090 Nested loops behaving strange.
+    if (isset($context['loop'])) {
+      return $context[$item];
+    }
+
     // The first test also finds empty / null render arrays
     if (!$context[$item] || isset($this->is_no_reference[$item])) {
       return $context[$item];
diff --git a/core/modules/views/views_ui/templates/views-ui-rearrange-filter-form.html.twig b/core/modules/views/views_ui/templates/views-ui-rearrange-filter-form.html.twig
new file mode 100644
index 0000000..083a8c1
--- /dev/null
+++ b/core/modules/views/views_ui/templates/views-ui-rearrange-filter-form.html.twig
@@ -0,0 +1,35 @@
+{#
+/**
+ * @file
+ * Default theme implementation for views ui rearrange filter form.
+ *
+ * Available variables:
+ * - override: @todo.
+ * - grouping: A boolean for if there is more than one group.
+ * - filter_groups_operator: @todo.
+ * - filter_groups_group: @todo.
+ * - ungroupable_table: @todo.
+ * - table: Filter's form table.
+ * - children: Child elements of the form that still need to be printed.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_views_ui_rearrange_filter_form()
+ *
+ * @ingroup themeable
+ */
+#}
+{% if override %}
+  {{ override }}
+{% endif %}
+<div class="scroll">
+  {% if grouping %}
+    {{ filter_groups_operator }}
+  {% else %}
+    {{ filter_groups_group }}
+  {% endif %}
+  {% if ungroupable_table %}
+    {{ ungroupable_table }}
+  {% endif %}
+  {{ table }}
+</div>
+{{ children }}
diff --git a/core/modules/views/views_ui/views_ui.module b/core/modules/views/views_ui/views_ui.module
index a17e215..8d1e23a 100644
--- a/core/modules/views/views_ui/views_ui.module
+++ b/core/modules/views/views_ui/views_ui.module
@@ -117,6 +117,7 @@ function views_ui_theme() {
     'views_ui_rearrange_filter_form' => array(
       'render element' => 'form',
       'file' => 'views_ui.theme.inc',
+      'template' => 'views-ui-rearrange-filter-form',
     ),
     'views_ui_expose_filter_form' => array(
       'render element' => 'form',
diff --git a/core/modules/views/views_ui/views_ui.theme.inc b/core/modules/views/views_ui/views_ui.theme.inc
index 841f15c..3aae41c 100644
--- a/core/modules/views/views_ui/views_ui.theme.inc
+++ b/core/modules/views/views_ui/views_ui.theme.inc
@@ -243,9 +243,15 @@ function theme_views_ui_reorder_displays_form($vars) {
 }
 
 /**
- * Turn the rearrange form into a proper table
+ * Prepares variables for Views UI rearrange filter form templates.
+ *
+ * Default template: views-ui-rearrange-filter-form.html.twig.
+ *
+ * @param array $variables
+ *   An associative array containing:
+ *   - form: A render element representing the form.
  */
-function theme_views_ui_rearrange_filter_form(&$vars) {
+function template_preprocess_views_ui_rearrange_filter_form(&$vars) {
   $form = $vars['form'];
   $rows = $ungroupable_rows = array();
   // Enable grouping only if > 1 group.
@@ -261,7 +267,11 @@ function theme_views_ui_rearrange_filter_form(&$vars) {
       // Title row, spanning all columns.
       $row = array();
       // Add a cell to the first row, containing the group operator.
-      $row[] = array('class' => array('group', 'group-operator', 'container-inline'), 'data' => drupal_render($form['filter_groups']['groups'][$group_id]), 'rowspan' => max(array(2, count($contents) + 1)));
+      $row[] = array(
+        'class' => array('group', 'group-operator', 'container-inline'),
+        'data' => $form['filter_groups']['groups'][$group_id],
+        'rowspan' => max(array(2, count($contents)  1)),
+      );
       // Title.
       $row[] = array('class' => array('group', 'group-title'), 'data' => '<span>' . $form['#group_options'][$group_id] . '</span>', 'colspan' => 4);
       $rows[] = array('class' => array('views-group-title'), 'data' => $row, 'id' => 'views-group-title-' . $group_id);
@@ -276,20 +286,37 @@ function theme_views_ui_rearrange_filter_form(&$vars) {
       if (!empty($form['remove_groups'][$group_id]['#type']) && $form['remove_groups'][$group_id]['#type'] == 'submit') {
         $form['remove_groups'][$group_id]['#attributes']['class'][] = 'js-hide';
       }
-      $row[] = array('colspan' => 5, 'data' => $instructions . drupal_render($form['remove_groups'][$group_id]));
+      $row[] = array('colspan' => 5, 'data' => $instructions . $form['remove_groups'][$group_id]);
       $rows[] = array('class' => array("group-message", "group-$group_id-message", $class), 'data' => $row, 'id' => 'views-group-' . $group_id);
     }
 
     foreach ($contents as $id) {
       if (isset($form['filters'][$id]['name'])) {
         $row = array();
-        $row[] = drupal_render($form['filters'][$id]['name']);
+         $row[]['data'] = $form['filters'][$id]['name'];
         $form['filters'][$id]['weight']['#attributes']['class'] = array('weight');
-        $row[] = drupal_render($form['filters'][$id]['weight']);
+        $row[]['data'] = $form['filters'][$id]['weight'];
         $form['filters'][$id]['group']['#attributes']['class'] = array('views-group-select views-group-select-' . $group_id);
-        $row[] = drupal_render($form['filters'][$id]['group']);
+        $row[]['data'] = $form['filters'][$id]['group'];
         $form['filters'][$id]['removed']['#attributes']['class'][] = 'js-hide';
-        $row[] = drupal_render($form['filters'][$id]['removed']) . l('<span>' . t('Remove') . '</span>', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $id, 'class' => array('views-hidden', 'views-button-remove', 'views-groups-remove-link', 'views-remove-link'), 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => TRUE));
+        $remove_link = array(
+          '#theme' => 'link',
+          '#path' => 'javascript:void()',
+          '#text' => '<span>' . t('Remove') . '</span>',
+          '#options' => array(
+            'attributes' => array(
+              'id' => 'views-remove-link-' . $id,
+              'class' => array('views-hidden', 'views-button-remove', 'views-groups-remove-link', 'views-remove-link'),
+              'alt' => t('Remove this item'),
+              'title' => t('Remove this item'),
+            ),
+            'html' => TRUE,
+          ),
+        );
+        $row[]['data'] = array(
+          $form['filters'][$id]['removed'],
+          $remove_link,
+        );
 
         $row = array('data' => $row, 'class' => array('draggable'), 'id' => 'views-row-' . $id);
         if ($group_id !== 'ungroupable') {
@@ -301,38 +328,62 @@ function theme_views_ui_rearrange_filter_form(&$vars) {
       }
     }
   }
+
+  unset($form['filters']);
   if (empty($rows)) {
     $rows[] = array(array('data' => t('No fields available.'), 'colspan' => '2'));
   }
 
-  $output = drupal_render($form['override']);
-  $output .= '<div class="scroll">';
+  if (isset($form['override'])) {
+    $variables['override'] = $form['override'];
+    unset($form['override']);
+  }
+
+  $variables['grouping'] = $grouping;
   if ($grouping) {
-    $output .= drupal_render($form['filter_groups']['operator']);
+     $variables['filter_groups_operator'] = $form['filter_groups']['operator'];
   }
   else {
+    // @todo find out what type these are to move the #title to the template.
     $form['filter_groups']['groups'][0]['#title'] = t('Operator');
-    $output .= drupal_render($form['filter_groups']['groups'][0]);
+    $variables['filter_groups_group'] = $form['filter_groups']['groups'][0];
   }
 
   if (!empty($ungroupable_rows)) {
     drupal_add_tabledrag('views-rearrange-filters-ungroupable', 'order', 'sibling', 'weight');
-    $header = array(t('Ungroupable filters'), t('Weight'), array('class' => array('views-hide-label'), 'data' => t('Group')), array('class' => array('views-hide-label'), 'data' => t('Remove')));
-    $output .= theme('table', array('header' => $header, 'rows' => $ungroupable_rows, 'attributes' => array('id' => 'views-rearrange-filters-ungroupable', 'class' => array('arrange'))));
+    $header = array(
+      t('Ungroupable filters'),
+      t('Weight'),
+      array('class' => array('views-hide-label'), 'data' => t('Group')),
+      array('class' => array('views-hide-label'), 'data' => t('Remove')),
+    );
+    $variables['ungroupable_table'] = array(
+      '#type' => 'table',
+      '#header' => $header,
+      '#rows' => $ungroupable_rows,
+      '#attributes' => array('id' => 'views-rearrange-filters-ungroupable', 'class' => array('arrange')),
+    );
   }
 
   // Set up tabledrag so that the weights are changed when rows are dragged.
   drupal_add_tabledrag('views-rearrange-filters', 'order', 'sibling', 'weight');
-  $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'views-rearrange-filters', 'class' => array('arrange'))));
-  $output .= '</div>';
+  $variables['table'] = array(
+    '#type' => 'table',
+    '#rows' => $rows,
+    '#attributes' => array('id' => 'views-rearrange-filters', 'class' => array('arrange')),
+  );
+
+  unset($form['filter_groups']);
+  unset($form['remove_groups']);
 
   // When JavaScript is enabled, the button for adding a new group should be
   // hidden, since it will be replaced by a link on the client side.
   $form['buttons']['add_group']['#attributes']['class'][] = 'js-hide';
 
   // Render the rest of the form and return.
-  $output .= drupal_render_children($form);
-  return $output;
+  // Remove elements from the 'children' render array.
+  // @todo Refactor when http://drupal.org/node/1920886 is resolved.
+  $variables['children'] = drupal_render_children($form);
 }
 
 /**
