Skip to content

How do custom APIs handle different templates? ​

If the site you’re looking to process provides different layouts or templates for the same URL structure or pages, you can still process data with a Diffbot Custom API.

There are two primary ways to handle differing layouts:

Comma-separate different selectors from different templates ​

By comma-separating your selectors, Diffbot’s Custom API will look for all possible matches when extracting data. So if one layout provides data using a class name of .favorites and another layout uses a class name of .likes, and you wish to extract either using the same field, you can use the selector of .likes,.favorites to support both templates/layouts. The “likes” and “favorites” data will be returned in your single field.

Create a different field for each data type in each layout ​

Diffbot Custom APIs will only return data for a field if its selectors are found on the page; empty fields will be suppressed. So you can also simply create a new field name for new fields on different templates.

For instance, in the above example, you could create one field named likes with a selector of .likes, and one field named favorites with a selector named .favorites. When .likes is found on a page, the likes field will be returned; when .favorites is found, the favorites field will be returned.