Template Options
In this section, you will learn about the structure of templates for parsing.
To create a template for parsing using the news-parser, follow these instructions based on the provided reference information:
- Begin by creating a template with the following structure: 
{
  "template": {
    "className": "[className]",
    "tagName": "[tagName]",
    "searchTemplate": "[searchTemplate]",
    "excludeTemplate":"[excludeTemplate]",
    "elementsTemplate":"[elementsTemplate]"
    "children": [
      {
        "tagName": "[tagName]",
        "searchTemplate": "[searchTemplate]",
        "position": "all"
      },
      // Add more child elements as needed
    ]
  },
  "extraOptions": {
    "addSrcSetAndSizes": false,
    "groupImagesRow": false,
    "addFeaturedMedia": false,
    "addSource": false
  },
  "postOptions": {},
  "aiOptions":{},
  "sidebarSeo":{},
  "userID": "[userID]"
}Replace [className], [tagName], [searchTemplate], and [userID] with the actual values for your template.
- In the template, the - "className"property represents the HTML class name of the tag that contains the post content. The- "tagName"property represents the tag name of the tag that contains the post content. The- "searchTemplate"property is the search pattern used to retrieve the node from the DOM, for example,- "div.pre-center". Syntax of "- searchTemplate"described here: https://simplehtmldom.sourceforge.io/docs/1.9/manual/finding-html-elements/
- The - "children"property is an array of child node elements that contain elements of the post data. Each child element has the same structure as the parent node, with- "tagName",- "searchTemplate", and- "position"properties.- "position"is currently set to- "all", indicating that all matching nodes should be retrieved. The child elements are specified in a single array without considering their nesting level.
- The - "extraOptions"property allows you to enable or disable additional options for the parsed data. Set the- "addSrcSetAndSizes"property to- trueif you want to add the- sizesattribute with image sizes breakpoints. Set- "groupImagesRow"to- trueto group images in Gutenberg blocks by two and arrange them in a row. Set- "addFeaturedMedia"to- trueif you want to include a featured media element in the post. Set- "addSource"to- trueif you want to add a link to the source page at the end of the post.
- The - "postOptions"property can be used to specify additional options for the parsed post.
- Finally, replace - [userID]with the relevant user ID associated with the template.
That's it! You now have a template structure for parsing using the news-parser. Customize the template according to your specific needs and use it with the news-parser to parse data from the provided URL or other URLs that match the template structure.
Last updated
