PDA

View Full Version : Genre and sub-genre



Jazz_North
07-24-2009, 07:23 PM
Is there any way to distinguish between Genre and Sub-Genre (from the Library tab) in a template? Both seem to be defined by "Genre" in the album properties in the template editor. I would like to use them systematically differently, but need to be able to distinguish them in a template.

Balok
07-31-2009, 12:55 AM
They're both in the <dax:genre> field. However, with just a little javascript you can crack that field (at least, until Andrei changes the format of it - but he won't do that! :))

Here's the code I used:



function showGenre(g,ssg)
{
if (g.indexOf(";") == -1)
document.write(g);
else
document.write(g.replace(/(.+);\s+(.+)/, ssg == 1 ? "$$1 ($$2)" : "$$1"));
}
I pass <dax:genre> to this function as the 'g' parameter. What I'm doing here is using a flag (that the user can set through the preferences) to specify whether to show the sub-genre.

The regular expression (between the '/' characters) extracts the two parts. You could crack the string the same way using String's split member. That code would look about like this:


function splitGenre(g)
{
var genreBits;
genreBits = g.split(/(.+);\s+(.+)/);

// genreBits[0] contains the genre
// genreBits[1] contains the subgenre
}


To call this from within your template, use code like this:



<script language="javascript">
splitGenre("<dax:genre/>");
</script>


Hope this helps.