Browse Source

add the no_cache parameter

Olivier Massot 5 năm trước cách đây
mục cha
commit
d2478dc988

+ 13 - 0
ot_templating/Classes/ViewHelpers/Request/WithPageViewHelper.php

@@ -8,6 +8,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
 
 /**
  *   Returns the current url with a 'page=' argument set up or updated
+ *   Warning: this viewhelper will also add a 'no_cache=1' argument to the query
  *
  *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  *
@@ -27,6 +28,12 @@ class WithPageViewHelper extends AbstractViewHelper {
             'int',
             "The page's number",
             true);
+        $this->registerArgument('nocache',
+            'int',
+            "If true, adds a no_cache parameter to the query",
+            false,
+            1
+        );
     }
 
     /**
@@ -44,6 +51,7 @@ class WithPageViewHelper extends AbstractViewHelper {
         RenderingContextInterface $renderingContext
     ) {
         $page = $arguments['page'];
+        $nocache = $arguments['nocache'];
 
         $request = $GLOBALS['TYPO3_REQUEST'];
         $uri = $request->getUri();
@@ -60,6 +68,11 @@ class WithPageViewHelper extends AbstractViewHelper {
         } else {
             $query .= "page=" . $page;
         }
+
+        $query = preg_replace("/&no_cache=1/", "", $query);
+        if ($nocache) {
+            $query .= '&no_cache=1';
+        }
         return (string)$uri->withQuery($query);
     }
 }