Page 1 of 1

How to access Product module output with jquery [solved]

Posted: Fri Oct 14, 2011 10:03 am
by chrisbt
I am attempting my first foray in ajax functionality. I have managed to achieve the desired result, but would like to know if there is a better way to achieve this.

I want to reload a product shortlist/wishlist from the Products module. The way I have achieved this initially is to create a blank template and dummy page 'tmp/shortlist.html' that just contains the output of:
{Products summarytemplate="Product_Thumbnails" productlist=$shortlist_ids pagelimit="6"}

Then using jquery I reload the html snippet when necessary with:

Code: Select all

$('#shortlist_content').load('tmp/shortlist.html');
While this works just fine. (I was amazed how easy it was!) I suspect there must be a more elegant way to get to the module output from javascript than having to create a dummy page. I am probably missing something pretty obvious, but can't find a solution so far in the forums.

Thanks

Chris

Re: How to access Product module output with jquery

Posted: Sat Oct 15, 2011 10:34 am
by applejack
Just create another CMS page which is hidden from the menu rather that a static HTML page and enter the same Products tag there. With jQuery load you can also load a specific div.

Re: How to access Product module output with jquery

Posted: Mon Oct 17, 2011 10:14 am
by chrisbt
Thanks for your reply applejack. I'll use jquery to load just the specific div as you suggest. But have realised that I can retrieve the current page and just use jquery to extract the specific div. This eliminates the messiness of having a dummy template & CMS page.
Cheers Chris.

Re: How to access Product module output with jquery [solved]

Posted: Mon Oct 17, 2011 10:37 am
by allan1412
Hi Chris

I was following your post because I'm doing something similar. Can I ask how you are retrieving the current page?

Thanks

Allan

Re: How to access Product module output with jquery [solved]

Posted: Tue Oct 18, 2011 1:03 pm
by chrisbt
Hi Allan, I retrieved the current page using:

Code: Select all

$('#shortlist').load(window.location.pathname + ' #shortlist'); 
with the "+ ' #shortlist' " appended to get jquery to select just the #shortlist element.

However I found this method of loading the whole page was a bit slower so I went back to loading a dummy page that only contains the shortlist content, using:

Code: Select all

$('#shortlist').load('tmp/shortlist.html&showtemplate=false');
This was noticeably faster so I decided to put up with the dummy but inactive CMS page.

Cheers, Chris

Re: How to access Product module output with jquery [solved]

Posted: Thu Oct 20, 2011 5:40 am
by allan1412
Hi Chris

Thanks for this - very helpful and much appreciated.

Allan