Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 6 of 6
  1. #1
    Senior Member
    Join Date
    Mar 2017
    Posts
    1,328

    Slim::Web::Pages->addPageFunction for index.html

    Material uses Slim::Web::Pages->addPageFunction to serve mobile.html and desktop.html - filling in the version via Slim::Web::HTTP::filltemplatefile How can I register a similar function for the main index.html - as in what do I pass to Slim::Web::Pages->addPageFunction?? I've tried '/', '/material/', 'index.html' and none seem to work.

    For the next release I want to combine the desktop and mobile layouts into a single index.html file - so that when the layout changes, the page does not need to be reloaded. I've made most of the changes, and it seems to work OK. However, Slim::Web::HTTP::filltemplatefile is used to alter the HTML returned so that the requested JS and CSS files have the correct revision.

    What I have at the moment is:
    Code:
            Slim::Web::Pages->addPageFunction( 'desktop', sub {
                my ($client, $params) = @_;
                $params->{'material_revision'} = $class->pluginVersion();
                return Slim::Web::HTTP::filltemplatefile('desktop.html', $params);
            } );
            Slim::Web::Pages->addPageFunction( 'mini', sub {
                my ($client, $params) = @_;
                $params->{'material_revision'} = $class->pluginVersion();
                return Slim::Web::HTTP::filltemplatefile('mini.html', $params);
            } );
            Slim::Web::Pages->addPageFunction( 'now-playing', sub {
                my ($client, $params) = @_;
                $params->{'material_revision'} = $class->pluginVersion();
                return Slim::Web::HTTP::filltemplatefile('now-playing.html', $params);
            } );
            Slim::Web::Pages->addPageFunction( 'mobile', sub {
                my ($client, $params) = @_;
                $params->{'material_revision'} = $class->pluginVersion();
                return Slim::Web::HTTP::filltemplatefile('mobile.html', $params);
            } );
    and what I'd like is something along the lines of:

    Code:
            Slim::Web::Pages->addPageFunction( 'index', sub {
                my ($client, $params) = @_;
                $params->{'material_revision'} = $class->pluginVersion();
                return Slim::Web::HTTP::filltemplatefile('index.html', $params);
            } );
    Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

  2. #2
    Senior Member
    Join Date
    Mar 2017
    Posts
    1,328
    Hmmm.... I can work around this with a raw handler, the following works:
    Code:
    my $ROOT_URL_PARSER_RE = qr{^\/material\/$}i;
    ...
    Slim::Web::Pages->addRawFunction($ROOT_URL_PARSER_RE, sub {
    ...
    but this does not:
    Code:
    my $ROOT_URL_PARSER_RE = qr{^\/material\/$}i;
    ...
    Slim::Web::Pages->addPageFunction($ROOT_URL_PARSER_RE, sub {
    ...
    Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

  3. #3
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,367

    Slim::Web::Pages->addPageFunction for index.html

    > Slim::Web::Pages->addPageFunction( 'index', sub {
    > my ($client, $params) = @_;
    > $params->{'material_revision'} = $class->pluginVersion();
    > return Slim::Web::HTTP::filltemplatefile('index.html', $params);
    > } );


    This way you'd try to overwrite a default page handler. That's probably
    not what you want to do. You should either create a new, independent
    page handler, or serve the un-changed template, which you then fill with
    data you get from an AJAX call.

    --

    Michael

  4. #4
    Senior Member
    Join Date
    Mar 2017
    Posts
    1,328
    Quote Originally Posted by mherger View Post
    > Slim::Web::Pages->addPageFunction( 'index', sub {
    > my ($client, $params) = @_;
    > $params->{'material_revision'} = $class->pluginVersion();
    > return Slim::Web::HTTP::filltemplatefile('index.html', $params);
    > } );


    This way you'd try to overwrite a default page handler. That's probably
    not what you want to do. You should either create a new, independent
    page handler, or serve the un-changed template, which you then fill with
    data you get from an AJAX call.
    Ah, ok. Thanks. I'll just use the raw handler - this seems to work.
    Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

  5. #5
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,367

    Slim::Web::Pages->addPageFunction for index.html

    > Ah, ok. Thanks. I'll just use the raw handler - this seems to work.
    But wouldn't this overwrite the other web interfaces?

    What you could do is call native Perl code from the page template
    instead
    (http://www.template-toolkit.org/docs...l#section_PERL).
    Or register a Template Toolkit plugin to be called from the template
    (http://www.template-toolkit.org/docs...l/Plugins.html - might be
    harder to get right).

    --
    --

    Michael

  6. #6
    Senior Member
    Join Date
    Mar 2017
    Posts
    1,328
    Quote Originally Posted by mherger View Post
    > Ah, ok. Thanks. I'll just use the raw handler - this seems to work.
    But wouldn't this overwrite the other web interfaces?

    What you could do is call native Perl code from the page template
    instead
    (http://www.template-toolkit.org/docs...l#section_PERL).
    Or register a Template Toolkit plugin to be called from the template
    (http://www.template-toolkit.org/docs...l/Plugins.html - might be
    harder to get right).
    Guess I need to look into this. My raw han der worked for '/material/' - but if Material is set as the default, then the handler is not called. :-(
    Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

Posting Permissions

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