Jump to content

Dynamicly replace url


LostKobrakai
 Share

Recommended Posts

I'm trying to dynamicly replace the url of products, if they are shown in a category context, so the url does reflect the correct path with the category included. But the url won't be replaced, while I can set a random new variable to the product pages.

		for ($i=0; $i < count($products); $i++) { 
			$products->eq($i)->of(false);

			$products->eq($i)->random = "hi$i";
			$products->eq($i)->url = "url";
			var_dump($products->eq($i)->random, $products->eq($i)->url);

			$products->eq($i)->of(true);
		}

This returns: string(27) "/shop/produkte/testprodukt/", string(3) "hi0"[/size].

Link to comment
Share on other sites

Or do a simple workaround:


for ($i=0; $i < count($products); $i++) { 
	// define a placeholder
	$products->eq($i)->link = $products->eq($i)->url; 
	
	
	$products->eq($i)->of(false);

	$products->eq($i)->random = "hi$i";
	
	// if you want to change the url you can now do it as simple as:
	$products->eq($i)->link = "url";
	var_dump($products->eq($i)->random, $products->eq($i)->link);

	$products->eq($i)->of(true);
}

// now go out and use "link" instead of "url"

Link to comment
Share on other sites

That's exactly what I did now. In the relavent templates I just call this, to get the changed value. 

$page->get("link|url");

I used this to have a two way url structure for categorized content: "…/articles/articlename/" and "…/category/categoryname/articlename/". Thinking about writing a short tutorial for this. 

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

Hi

Seems awkward to answer a so old post, but since I don't know what exactly searching for, I found this one with the exact same goal : adding category in the url.

Unfortunately, I'm not sure to understand what to do. @LostKobrakai, by any chance, did you wrote this tutorial?

Thanks

Mélanie

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...