Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted February 20, 20196 yr 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
February 20, 20196 yr Author 29 minutes ago, Adriano Faria said: This seems wrong: forum-{$forumid} Or do you print it directly in template? Yes, to <body class="">
February 20, 20196 yr 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; } }}
February 20, 20196 yr Author 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.
February 20, 20196 yr 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}}
Archived
This topic is now archived and is closed to further replies.