Script Function - fatsecret.addRef(section, element_id)

Description

If the auto_template script URL parameter is set to "false", the predefined templates will not be loaded and you will have to provide your own layout for each canvas. This provides one way to set up the canvas content (the other being fatsecret.writeHolder).
fatsecret.addRef will replace any HTML element on the page with ID of element_id with the specified section (see Canvas Reference for the complete section list for each canvas).

Parameters

Required

Name Type Description
section String The name of the section to load.
element_id String The ID of the HTML element to replace.

Example

Setting up a simple layout for the food.get canvas.
<script src="https://platform.fatsecret.com/js?key=XXXXX&auto_template=false"></script>

<div id="search"></div>
<div id="food_title"></div>
<div id="nutrition_panel"></div>

<script>
fatsecret.addRef("search", "search");
fatsecret.addRef("foodtitle", "food_title");
fatsecret.addRef("nutritionpanel", "nutrition_panel");
</script>
Figure 1: Using fatsecret.addRef to set up a custom layout for the food.get canvas
FatSecret Sites
For Developers

For Professionals

For Everyone

FatSecret Platform API

Support
API

About FatSecret

© 2021 FatSecret. All rights reserved.