This website is geared towards distributors of swisstopo products and web developers. If you would like to buy products from swisstopo, please visit the swisstopo onlineshop.
In this section, you can find out how to incorporate selected products from the swisstopo onlineshop into your website manually, in four easy steps.
A JavaScript file must be integrated into each page on which you would like the swisstopo products to be displayed. You can do this by copying the following “snippet” and pasting it into the header (<head>) of the website:
<script language="javascript" src="http://www.toposhop.admin.ch/static/javascripts/products/productList.js" type="text/javascript"> </script>
New code from January 1st 2017 <script language="javascript" src="http://www.swisstopoproducts.ch/javascript/productList.js" type="text/javascript"> </script>
To insert the data into an existing layout in the most flexible way possible, a layout will need to be created with the necessary placeholders. This layout will be used and displayed for each product. The placeholders are indicated by square brackets []. You can find out which attributes can be used here in the section «Available attributes».
var formatTemplate = '<tr>' + '<td>[product.titleDe]</td>' + '<td>[product.descriptionDe]</td>' + '<td>[product.price]</td>' + '<td>[product.releaseDate]</td>' + '<td><a href="#">Bestellen</a></td>' + '</tr>';
To load the data from swisstopo, you will need to call up the JavaScript method getProducts(). This loads the required
product data in the background without preventing the page from loading (Ajax). For the function to be called up while
the page is loading, it must be integrated into a Windows load listener. This can be done using the following command:
window.onload=getProducts(...).
The function requires four parameters:
window.onload=getProducts(1.0, formatTemplate, [],[]);
The final step involves creating what is known as a “container”. The content of this container will ultimately be the list of products. A typical container is an HTML <div> element, although in the example below it can also be a <tbody> element. The element must be assigned the following identification: id=”productOutputContainer”. This ID enables the container to be referenced from the JavaScript code.
<div id="productOutputContainer"></div> <tbody id="productOutputContainer"></tbody>