Favorites Documentation

Favorites:Info Template Tag

The Favorites:Info tag is one of the essential Favorites tags, used for dislaying saved favorites data (looped) on each entry or member for the currently logged in user, as well as handles formatting for the Favorites:Form and Favorites:Edit tags.

{exp:favorites:info} content {/exp:favorites:info}

Parameters

The following parameters are available for use:

collection=

collection="articles"

This parameter allows you to filter the favorites results by collection name. Do not specify this parameter if you want ALL favorites of all collections to show.

collection_id=

collection_id="1"

This parameter allows you to filter the favorites results by collection ID. Do not specify this parameter if you want ALL favorites of all collections to show.

entry_id=

entry_id="{entry_id}"

If you're wanting to display favorites data for channel entries, this is a required parameter. You'll typically nest the Favorites:Info tag within the Channel:Entries tag, so simply feed this parameter with the {entry_id} variable.

member_id=

member_id="{member_id}"

If you're wanting to display favorites data for members, this is a required parameter. You'll typically nest the Favorites:Info tag within a member template tag from an add-on such as User or the Member:Custom_Profile_Data tag, so simply feed this parameter with the {member_id} variable.

limit=

limit="25"

This parameter allows you to determine the maximum number of results you want to show on the page.

paginate=

paginate="both"

This parameter allows you to control where the pagination will display. Options are top, bottom, or both. Used in conjunction with the favorites:paginate variable pair.

disable_pagination=

disable_pagination="yes"

The Favorites:Info tag is used in a wide variety of conditions, and because it does support pagination itself, if placed within another template tag that uses pagination, it will interfere with the Favorites:Info displaying data properly. To disable pagination in Favorites:Info to avoid this issue, call this parameter and specify a value of yes. Note: this will turn off pagination for this tag.

Variables

The following variables are available for use:

favorites:absolute_count

{favorites:absolute_count}

The Favorites:Info tag is a looping tag, so for every existing favorite for the entry or member, it'll loop through. This variable outputs the display order number for each result in the list of results (across all pages, if using pagination).

favorites:absolute_results

{favorites:absolute_results}

The Favorites:Info tag is a looping tag, so for every existing favorite for the entry or member, it'll loop through. This variable will return the absolute total amount of results. This includes all results across all pages when pagination is used.

favorites:count

{favorites:count}

The Favorites:Info tag is a looping tag, so for every existing favorite for the entry or member, it'll loop through. This variable outputs the display order number for each result in the list (within the page, if using pagination).

favorites:total_results

{favorites:total_results}

The Favorites:Info tag is a looping tag, so for every existing favorite for the entry or member, it'll loop through. This variable outputs the total amount of results in the list (within the page, if using pagination). You would typically use this in a conditional statement.

favorites:collection_name

{favorites:collection_name}

This variable displays the collection name that the entry or member was saved to for the currently logged in user.

favorites:favorited_date

{favorites:favorited_date format="%l, %F %j, %Y at %g:%i %a"}

This variable displays the date/time of when the entry or member was saved to the currently logged in users' favorites. This requires the format parameter in order to define how the date should be displayed.

favorites:notes

{favorites:notes}

This variable displays the notes the currently logged in user supplied for the entry or member when they saved it as a favorite.

Variable Pairs

The following variable pairs are available for use:

favorites:paginate

{favorites:paginate}
    Page {favorites:current_page} of {favorites:total_pages} pages
    {favorites:pagination_links}
{/favorites:paginate}

OR

{favorites:paginate}
    <ul class="pagination">
    {favorites:pagination_links}
        {first_page}
            <li><a href="{pagination_url}">First</a></li>
        {/first_page}
        {previous_page}
            <li><a href="{pagination_url}">&laquo; Previous</a></li>
        {/previous_page}
        {page}
            <li{if current_page} class="active"{/if}><a href="{pagination_url}">{pagination_page_number}</a></li>
        {/page}
        {next_page}
            <li><a href="{pagination_url}">Next &raquo;</a></li>
        {/next_page}
        {last_page}
            <li><a href="{pagination_url}">Last</a></li>
        {/last_page}
    {/favorites:pagination_links}
    </ul>
{/favorites:paginate}

Pagination is available for this tag and works just like regular EE pagination, but each variable/variable pair is prepended with favorites: (except for any variables and variable pairs inside of the favorites:pagination_links variable pair). Used in conjunction with the paginate parameter.

Conditionals

The following conditionals are available for use:

favorites:no_results

{if favorites:no_results}
    Sorry, there are no results.
{/if}

This conditional is shows its contents when there are no results, under the given parameters.

Examples

The following is a very basic example that shows the Favorites:Info tag displaying saved favorite information for the currently logged in user:

{exp:channel:entries}
    <h2>{title}</h2>
    <p>{body}</p>
    <p>
    {exp:favorites:info
        entry_id="{entry_id}"
        disable_pagination="yes"
    }
        You saved this to {favorites:collection_name}
        on {favorites:favorited_date format="%F %j, %Y"}
        {if favorites:notes} with the notes: <i>{favorites:notes}</i>{/if}
    {/exp:favorites:info}
    </p>
{/exp:channel:entries}

The following is a more elaborate example, with some logic built in for hiding the "Add to favorites" form if the user has already favorited the entry, displaying info about the saved entry, and including ability to edit favorites using the Favorites:Edit tag:

{exp:channel:entries}
    <h2>{title}</h2>
    <p>{body}</p>
<!-- DISPLAY the current favorites. This won't parse if there are no favorites for the item yet. -->
    {exp:favorites:info
        entry_id="{entry_id}"
        disable_pagination="yes"
    }
        <p>
            You saved this to {favorites:collection_name}
            on {favorites:favorited_date format="%F %j, %Y"}
            {if favorites:notes} with the notes: <i>{favorites:notes}</i>{/if}
        </p>
    <!-- EDIT this current favorite -->
        <p>
        {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}" />
            <input type="submit" name="submit" value="Update" />
        {/exp:favorites:edit}
    <!-- DELETE the current favorite -->
        {exp:favorites:edit
            favorite_id="{favorites:favorite_id}"
        }
            <input type="hidden" name="delete" value="yes">
            <input type="submit" name="submit" value="Remove" />
        {/exp:favorites:edit}
        </p>
    {if favorites:no_results}
        <p>
    <!-- ADD a Favorite -->
        {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" />
            <input type="submit" name="submit" value="Add" />
        {/exp:favorites:form}
        </p>
    {/if}
    {/exp:favorites:info}
{/exp:channel:entries}

The following is an example for adding/updating/removing members from favorites (with suggested, but not limited to, use of User add-on):

{exp:user:users}
    <h2><a href="{path='user/profile'}">{screen_name}</a></h2>
    <p>Location: {location}</p>
    <p>Bio: {bio}</p>
<!-- DISPLAY the current favorites. This won't parse if there are no favorites for the item yet. -->
    {exp:favorites:info
        member_id="{member_id}"
        disable_pagination="yes"
    }
        <p>
            You saved this to {favorites:collection_name}
            on {favorites:favorited_date format="%F %j, %Y"}
            {if favorites:notes} with the notes: <i>{favorites:notes}</i>{/if}
        </p>
    <!-- EDIT this current favorite -->
        <p>
        {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}" />
            <input type="submit" name="submit" value="Update" />
        {/exp:favorites:edit}
    <!-- DELETE the current favorite -->
        {exp:favorites:edit
            favorite_id="{favorites:favorite_id}"
        }
            <input type="hidden" name="delete" value="yes">
            <input type="submit" name="submit" value="Remove" />
        {/exp:favorites:edit}
        </p>
    {if favorites:no_results}
        <p>
    <!-- ADD a Favorite -->
        {exp:favorites:form
            member_id="{member_id}"
        }
            <select name="collection">
            {favorites:collections}
                <option value="{favorites:collection}">
                    {favorites:collection}
                </option>
            {/favorites:collections}
            </select>
            <input type="text" name="notes" />
            <input type="submit" name="submit" value="Add" />
        {/exp:favorites:form}
        </p>
    {/if}
    {/exp:favorites:info}
{/exp:user:users}

Support

Having problems setting up and/or using Favorites? Support is offered from 10am to 4pm EST weekdays. Send us an email at help@eeharbor.com and we will respond as quickly as we can.