Jump to content

Template Error (OutOfRangeException::0)


Gesundheit

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...