Pedro Silva  committed 65fb782

Perform template field substitution on albums

- adds another traversal through all plugins' template_fields for each
'evaluate_template' call.
- requires the following idiom (or equivalent):

def _tmpl_field(album):
"""Return stuff.
if isinstance(album, Album):
return stuff

  • Participants
  • Parent commits 0e13249

Comments (0)

Files changed (2)

File beets/

         mapping['artpath'] = displayable_path(mapping['artpath'])
         mapping['path'] = displayable_path(self.item_dir())
+        # Get values from plugins.
+        for key, value in plugins.template_values(self).iteritems():
+            mapping[key] = value
         # Get template functions.
         funcs = DefaultTemplateFunctions().functions()

File docs/plugins/writing.rst

 With this plugin enabled, templates can reference ``$disc_and_track`` as they
 can any standard metadata field.
+Note that the above idiom expects the argument ``item`` to be an
+actual *track* item. If you'd like to provide a template field for
+*albums*, you'll need to check the argument::
+    @MyPlugin.template_field('field')
+    def _tmpl_field(album):
+        """Return stuff.
+        """
+        if isinstance(album, beets.library.Album):
+            return 'stuff'
 Extend MediaFile