Favorites Info Tag Examples
The {exp:favorites:info} tag is a looping tag that displays favorite data for entries, members, or files that have been saved by the currently logged-in user. It's one of the essential Favorites tags, used for displaying saved favorites data and handling formatting for the Favorites:Form and Favorites:Edit tags.
The tag works with three types of content:
- Channel entries - Use the
entry_idparameter - Members - Use the
member_idorusernameparameter - Files - Use the
file_idparameter
The tag will only display content if the item has been favorited by the currently logged-in user. If the item hasn't been favorited, you can use the {favorites:no_results} conditional to show alternative content, such as a form to add the item to favorites.
Example 1: Basic Usage
The simplest use of the Info tag displays basic favorite information for an entry:
{exp:favorites:info entry_id="{entry_id}"}
<p>Saved to {favorites:collection_name} on {favorites:favorited_date format="%F %j, %Y"}</p>
{if favorites:notes}
<p>Notes: {favorites:notes}</p>
{/if}
{/exp:favorites:info}
Explanation:
- The
entry_idparameter is required when displaying favorites for channel entries. You'll typically nest the Favorites:Info tag within the Channel:Entries tag, so simply feed this parameter with the{entry_id}variable. {favorites:collection_name}displays the name of the collection the entry was saved to.{favorites:favorited_date}displays when the entry was saved. Theformatparameter is required to define how the date should be displayed. In this example, it shows the full month name, day, and year.{favorites:notes}displays any notes the user supplied when saving the favorite. The{if favorites:notes}conditional ensures this only displays if notes exist.- This tag only displays content if the entry has been favorited by the currently logged-in user. If not favorited, nothing will display.
Example 2: Using with Albums (Files)
When working with files, you can use the include_albums parameter to display albums alongside favorite information. This is useful when a file might be in an album even if it hasn't been favorited:
{exp:favorites:info file_id="{file_id}" include_albums="yes"}
{if is_favorite}
<p>Saved to {favorites:collection_name}</p>
{/if}
{albums}
<p>In album: {album_name}</p>
{/albums}
{/exp:favorites:info}
Explanation:
- The
file_idparameter is required when displaying favorites for files. You'll typically nest the Favorites:Info tag within a File:Entries tag (or equivalent), so simply feed this parameter with the{file_id}variable. - The
include_albums="yes"parameter includes files that are in albums (even if not favorited) in the results. This allows you to display album information alongside favorites data. - The
{albums}variable pair loops through all albums the file belongs to. Available variables within this pair includealbum_name,album_id,privacy,created_date, andfile_count. - The
is_favoritevariable (also available as{favorites:is_favorite}) outputs "1" if the item is favorited by the specified user, and an empty string if not. This allows you to conditionally display favorite-specific information. - When
include_albums="yes"is used, albums will display even if the file isn't favorited, making it useful for showing all organizational data for a file.
Example 3: Complete Form Integration
The Info tag is most powerful when used in conjunction with the Form and Edit tags to provide complete CRUD (Create, Read, Update, Delete) functionality:
{exp:favorites:info entry_id="{entry_id}"}
<div class="favorite-info">
<p>Saved to {favorites:collection_name} on {favorites:favorited_date format="%F %j, %Y"}</p>
{if favorites:notes}
<p>Notes: {favorites:notes}</p>
{/if}
<!-- Edit form -->
{exp:favorites:edit favorite_id="{favorites:favorite_id}"}
<select name="collection">
{favorites:collections}
<option value="{favorites:collection}" {favorites:selected}>
{favorites:collection}
</option>
{/favorites:collections}
</select>
<input type="text" name="notes" value="{favorites:notes}" />
<button type="submit">Update</button>
{/exp:favorites:edit}
<!-- Delete form -->
{exp:favorites:edit favorite_id="{favorites:favorite_id}"}
<input type="hidden" name="delete" value="yes">
<button type="submit">Remove</button>
{/exp:favorites:edit}
</div>
{if favorites:no_results}
<!-- Add form -->
{exp:favorites:form entry_id="{entry_id}"}
<select name="collection">
{favorites:collections}
<option value="{favorites:collection}">
{favorites:collection}
</option>
{/favorites:collections}
</select>
<input type="text" name="notes" />
<button type="submit">Add to Favorites</button>
{/exp:favorites:form}
{/if}
{/exp:favorites:info}
Explanation:
- The
{favorites:no_results}conditional displays content when the item is NOT favorited by the currently logged-in user. This is the opposite of the main tag content, which only displays when the item IS favorited. - When an item is favorited, the main content displays showing the favorite information and edit/delete forms.
- The
{exp:favorites:edit}tag is used to update or delete an existing favorite. It requires thefavorite_idparameter, which is available from the Info tag as{favorites:favorite_id}. - The
{favorites:collections}variable pair loops through all available collections. Within this pair,{favorites:collection}outputs the collection name, and{favorites:selected}outputs "selected" for the current collection, allowing you to pre-select it in a dropdown. - To delete a favorite, use the
{exp:favorites:edit}tag with a hidden input fieldname="delete" value="yes". This removes the favorite when the form is submitted. - When an item is not favorited, the
{favorites:no_results}conditional displays the{exp:favorites:form}tag, which allows users to add the item to their favorites. - The relationship between these tags: Info displays the data and provides the
favorite_idneeded for Edit, while theno_resultsconditional determines whether to show the Form (add) or the main content with Edit (update/delete).
Key Parameters
entry_id- Required for entries. Specify the channel entry ID.file_id- Required for files. Specify the file ID.member_id- Required for members. Specify the member ID.username- Alternative to member_id. Specify a username and Favorites will look up the member ID automatically.collection- Filter favorites by collection name. Do not specify if you want all favorites of all collections to show.collection_id- Filter favorites by collection ID. Do not specify if you want all favorites of all collections to show.include_albums- When set to "yes" and type is "file", includes files that are in albums (even if not favorited) in the results. Default is "no".disable_pagination- Set to "yes" to disable pagination. Useful when the tag is nested within another tag that uses pagination.limit- Determine the maximum number of results to show on the page.offset- Skip a specified number of results before starting to display favorites.
Key Variables
{favorites:collection_name}- Name of the collection the item was saved to.{favorites:favorited_date}- Date/time when the item was saved. Requires theformatparameter to define how the date should be displayed.{favorites:notes}- Notes the user supplied when saving the favorite.{favorites:favorite_id}- ID of the favorite. Required for the Edit tag to update or delete the favorite.{favorites:count}- Current row number (within the page, if using pagination).{favorites:total_results}- Total amount of results in the list (within the page, if using pagination).{favorites:absolute_count}- Display order number for each result (across all pages, if using pagination).{favorites:absolute_results}- Absolute total amount of results (includes all results across all pages when pagination is used).{is_favorite}/{favorites:is_favorite}- Outputs "1" if the item is favorited by the specified user (or current user if favoriter_id is not specified), and empty string if not.{albums}- Variable pair for albums (wheninclude_albums="yes"). Available variables includealbum_name,album_id,privacy,created_date, andfile_count.{favorites:no_results}- Conditional that displays content when the item is NOT favorited by the currently logged-in user.