Start a new topic

Create urls

I have a custom project in my storefront solution, and in there I want to generate links to products and product images. Is there a nice way to do this?

I hope I can avoid making them manual like this:

var prodUrl = "/product/" + prodId;

var imgUrl = "http://localhost/admin/assets/catalog/" + imgName;

This product link gives me an exception in StorefrontUrlBuilder(L:96), null virtualPath, when I click it on the index page. Works from other pages.

In the image link, I need to know where the admin page is.


As I right understand you asking for generation links in JS?

No, in a cs class.

For generate product link in managed code need to use StorefrontUrlBuilder. 



urlBuilder.ToAppRelative("~/product/" + product.Id)


 or SEO friendly url:


 urlBuilder.ToAppRelative("~/" + product.SeoInfo.Slug)


Product image have property Url which always contains absolute url and you may use it directly.

But I do not recommend generate Url on server code better it will do it on Liquid templates trough filters.

Login or Signup to post a comment