Is there a simple way to grab the full current url params as is so I can add to other links on the page (retaining all the current params)
i.e. if I have for instance product list page:
search-results-page.html?¶m1=Something+Here¶m2=Something¶m3=Somevalue etc..
and I want links to the product page to be
product-item-page.html?¶m1=Something+Here¶m2=Something¶m3=Somevalue etc..
I’m hoping this can be done without getting each var individually maybe?
thanks all
-
☆ A M B ☆
- 24,524 Posts
You can use a snippet to get the $_SERVER[’REQUEST_URI’] then break it at the ? using explode() and then append the query string part onto your links.
Be careful; if you are using friendly URLs you’ll need the first ?, but if you are not using friendly URLs the index.php?id=xx uses that ? so the first name=value pair will need to start with &.
great thanks Susan, I’ll give it a go..
-
☆ A M B ☆
- 24,524 Posts
You should always have a return; statement at the very last line in a snippet just in case it gets that far. It probably won’t hurt anything as it is, but it’s a good habit to get into.
good point, thanks Susan..
Just an idea, but if you are running this snippet in a bunch of places on the same page, it might be more efficient to use a placeholder setup like so:
Call the snippet in the top of the template to set the placeholder.
<?php
if(isset($_SERVER['REQUEST_URI'])) {
$myURI = $_SERVER['REQUEST_URI'];
$params = explode('?', $myURI);
if($params[1] != '') {
//$output = '?'.$params[1];
//return $output;
$modx->setPlaceholder('uri_params', '?'.$params[1]); // [+uri_params+]
}
}
?>
Then tack on the placeholder to the links: a href="[~XX~][+uri_params+]"
great idea, thanks Breezer, certainly would be much more efficient as I’m using it in a chunk for a list of products.