Gesundheit Posted February 20, 2019 Share Posted February 20, 2019 Hello, I'm using: {{if request.module == 'forums' && request.controller == 'topic'}} {{$topic = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id );}} {{$forumid = $topic->container()->id;}} forum-{$forumid} {{endif}} in globalTemplate to get the forum ID for styling purposes. It does its job, however, if users view topics they lack access to, they're presented with a: [[Template core/front/global/globalTemplate is throwing an error. This theme may be out of date. Run the support tool in the AdminCP to restore the default theme.]] which logs as a template error: OutOfRangeException::0 Link to comment Share on other sites More sharing options...
Adriano Faria Posted February 20, 2019 Share Posted February 20, 2019 This seems wrong: forum-{$forumid} Or do you print it directly in template? Link to comment Share on other sites More sharing options...
Gesundheit Posted February 20, 2019 Author Share Posted February 20, 2019 29 minutes ago, Adriano Faria said: This seems wrong: forum-{$forumid} Or do you print it directly in template? Yes, to <body class=""> Link to comment Share on other sites More sharing options...
bfarber Posted February 20, 2019 Share Posted February 20, 2019 You're using loadAndCheckPerms() so naturally if the user does not have access then they will run into an error. You can try something like this instead: {{ try{ $forumId = \IPS\forums\Forum::loadAndCheckPerms( \IPS\Request::i()->id )->_id; } catch( \OutOfRangeException $e ){ $forumId = 0; } }} Link to comment Share on other sites More sharing options...
Gesundheit Posted February 20, 2019 Author Share Posted February 20, 2019 19 minutes ago, bfarber said: You're using loadAndCheckPerms() so naturally if the user does not have access then they will run into an error. You can try something like this instead: {{ try{ $forumId = \IPS\forums\Forum::loadAndCheckPerms( \IPS\Request::i()->id )->_id; } catch( \OutOfRangeException $e ){ $forumId = 0; } }} I tried: {{if request.module == 'forums' && request.controller == 'topic'}} {{$topic = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id );}} {{ try{ $forumId = $topic->container()->id; } catch( \OutOfRangeException $e ){ $forumId = 0; } }} forum-{$forumId} {{endif}} but it's still giving unauthorized users a template error. Link to comment Share on other sites More sharing options...
bfarber Posted February 20, 2019 Share Posted February 20, 2019 6 minutes ago, Gesundheit said: I tried: {{if request.module == 'forums' && request.controller == 'topic'}} {{$topic = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id );}} {{ try{ $forumId = $topic->container()->id; } catch( \OutOfRangeException $e ){ $forumId = 0; } }} forum-{$forumId} {{endif}} but it's still giving unauthorized users a template error. The line calling loadAndCheckPerms() needs to be wrapped in the try/catch, as that's where the error is thrown. {{if request.module == 'forums' && request.controller == 'topic'}} {{ try{ $forumId = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id )->container()->id; } catch( \OutOfRangeException $e ){ $forumId = 0; } }} forum-{$forumId} {{endif}} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.