PDA

View Full Version : Javascript external file paths



paul
29-09-2007, 13:13
I have some javascript working on a product page. Taken from this source
http://dynamicdrive.com/dynamicindex17/ajaxtabscontent/index.htm

It references and pulls in content from external files on the same domain and displays in tabs on a product page. its working and displaying very well.

The file references are along the lines of:
"/user/content/tabcontent1.htm" - to display in tab 1
"/user/content/tabcontent2.htm" - to display in tab 2

the javascript code is currently entered on the product editor page.

My object is to have the main javascipt entered on the category editor page and therefore displaying for all products within. The product paths however need to reference different files relating to each product as the content will be different for each product.

A filepath for each product would therefore be something like:
for sku1:
"/user/content/sku1/tabcontent1.htm"
"/user/content/sku1/tabcontent2.htm"
"/user/content/sku1/tabcontent3.htm"

for sku2:
"/user/content/sku2/tabcontent1.htm"
"/user/content/sku2/tabcontent2.htm"
"/user/content/sku2/tabcontent3.htm"

now for the potential time saving bit - is there a way of replacing "sku_x" dynamically to reference the sku for each product page? i would only then need to create a folder for each sku and save the content in tabcontent1.htm, tabcontent2.html..... I would not need to create different file references on each product editor page.

i only ask this as i recently discovered you could reference the domain dynamically ("+window.location.hostname+"/) otherwise i wouldnt have imagined this would be possible.

sorry for the long post but hope its clear:confused:

Rich
30-09-2007, 15:27
Hi Paul, I feel that this is possibly not the best type of script to use for a dynamic site. External files are a bad idea, as they introduce content that's not in the Bluepark database, they have to be stored separately, and they have to be edited separately from other product data. A better solution would be a single JavaScript file in the Template Editor, included on every page automatically.

Then, the Page Content field would simply require some tags adding around your HTML content. Here's the kind of example I would use:

http://www.barelyfitz.com/projects/tabber/

Some other downsides to the proposed method:

To make lots of dynamic replacements on a page slows down the rendering of the site. Also, having a large portion of JavaScript code on each page is far less tidy than simply linking to an external file. Finally, I should mention that any JavaScript code you include in the Category Editor is not displayed on the product pages within.

See how you get on with the example I gave above, this is the kind of system you want. I think there are some similar examples on Dynamic Drive. The tabbed system in Bluepark's Admin Console works in a very similar way.

paul
30-09-2007, 20:33
That works much better. I simply got confused and was making it more complicated than it needed to be.

Thanks.