Results 1 to 2 of 2

Thread: Genre and sub-genre

  1. #1
    Join Date
    Oct 2006
    Location
    Posts
    304

    Default Genre and sub-genre

    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.

  2. #2
    Join Date
    Feb 2004
    Location
    Posts
    157

    Thumbs up

    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:

    Code:
    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:
    Code:
    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:

    Code:
    <script language="javascript">
    splitGenre("<dax:genre/>");
    </script>
    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •