Template Tags — django-lastfm v0.1 documentation

### Navigation

- index
- modules |
- next |
- previous |
- django-lastfm v0.1 documentation »
- API-Reference »

# Template Tags

Django-lastfm contains only one template tag in `lastfm.templatetags.lastfm_widget` that is used to load a context object with all necessary data.

## Usage of the template tag

This module defines a single template tag that will return a context object for your Last.fm widget. It contains a title for the widget and a `<div>` container. This container includes the AJAX code that retrieves the data from the `lastfm` view and generates an image for each item.

    {% load lastfm_widget %}

    {% get_lastfm_widget as lastfm_widget %}
    <h2>{{ lastfm_widget.title }}</h2>
    {{ lastfm_widget.content }}

The generated code will roughly look like this:

    <div class="lastfm">
        <div><a><img /></a></div>
        <div><a><img /></a></div>
        <!-- ... -->
    </div>

The surrounding `<div>` has the CSS class lastfm. You can use this to customize the style of the widget. This how it could look like:

    #sidebar > #lastfm {
        min-height: 225px; /* required due to "float: left" in the next sec. */
    }

    #sidebar #lastfm div {
        width: 54px;
        height: 39px;
        overflow: hidden;
        float: left;
        border: 1px solid white;
        -moz-border-radius: 2px;
        -khtml-border-radius: 2px;
        border-radius: 2px;
        margin: 0px 2px 4px 2px;
    }

    #sidebar #lastfm div:active, #sidebar #lastfm div:hover {
        border-color: #9FC765;
    }

    #sidebar #lastfm img {
        width: 54px;
        min-height: 39px;
    }

## Implementation

As for every template tag, there is a compilation function (`get_lastfm_widget()`) and a renderer (`LastfmWidgetNode`) that do all the work.

class `lastfm.templatetags.lastfm_widget.` `LastfmWidgetNode`(var_name)
  This class will create a context object named `var_name`. It will contain the `title` and the `content` of the widget.

`lastfm.templatetags.lastfm_widget.` `get_lastfm_widget`(parser, token)
  Get the variable name for the widget from the template tag.

### Navigation

- index
- modules |
- next |
- previous |
- django-lastfm v0.1 documentation »
- API-Reference »