Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted August 16, 20222 yr Hello, can we check if we're on the default page (for example with changed default app)? Thanks in advance!
August 16, 20222 yr These work for me: Default app: $defaultApp = \IPS\Application::load(\IPS\Request::i()->app)->default; Default module: $defaultModule = \IPS\Application\Module::get(\IPS\Request::i()->app, \IPS\Request::i()->module)->default;
August 16, 20222 yr Author Hm, load app info every page check isn't much efficient. Maybe someone else has better idea. But thanks for sharing it!
August 16, 20222 yr a possible solution is to check the data in the \IPS\Request::i()->url() method. if it is the default app on the "homepage", then ->path should be empty: IPS\Http\Url\Friendly Object ( [url:protected] => https://dev.codingjungle.com/ [data] => Array ( [scheme] => https [host] => dev.codingjungle.com [port] => [user] => [pass] => [path] => / [query] => [fragment] => ) [queryString] => Array ( ) [hiddenQueryString] => Array ( [app] => stratagem [module] => view [controller] => projects ) [seoPagination] => [base] => front [seoTemplate] => stratagem [seoTitles] => Array ( ) [friendlyUrlComponent] => ) otherwise it will be populated with the path from the furl: IPS\Http\Url\Friendly Object ( [url:protected] => https://dev.codingjungle.com/stratagem [data] => Array ( [scheme] => https [host] => dev.codingjungle.com [port] => [user] => [pass] => [path] => /stratagem [query] => [fragment] => ) [queryString] => Array ( ) [hiddenQueryString] => Array ( [app] => stratagem [module] => view [controller] => projects ) [seoPagination] => [base] => front [seoTemplate] => stratagem [seoTitles] => Array ( ) [friendlyUrlComponent] => stratagem ) there might be a caveat to this, as i haven't fully tested this. it was something off the top of my head. 45 minutes ago, IPCommerceFan said: These work for me: Default app: $defaultApp = \IPS\Application::load(\IPS\Request::i()->app)->default; Default module: $defaultModule = \IPS\Application\Module::get(\IPS\Request::i()->app, \IPS\Request::i()->module)->default; 37 minutes ago, DawPi said: Hm, load app info every page check isn't much efficient. Maybe someone else has better idea. But thanks for sharing it! btw this could be a good method too, as applications and modules get cached, so it shouldn't cost anything noticeable in loads, well nothing more than most servers can afford to use.
August 16, 20222 yr Solution plus \IPS\Dispatcher already loads these values: $app = null; $module = null; if(\IPS\Dispatcher::hasInstance()){ $dispatcher = \IPS\Dispatcher::i(); $app = $dispatcher->application; $module = $dispatcher->module; } if($app !== null && $app->default && $module->default){ //if we are here, we on the default app/module, lets do our thing } Edited August 16, 20222 yr by CodingJungle
August 16, 20222 yr Author 29 minutes ago, CodingJungle said: plus \IPS\Dispatcher already loads these values: $app = null; $module = null; if(\IPS\Dispatcher::hasInstance()){ $dispatcher = \IPS\Dispatcher::i(); $app = $dispatcher->application; $module = $dispatcher->module; } if($app !== null && $app->default && $module->default){ //if we are here, we on the default app/module, lets do our thing } That should be best solution for me. Thanks!
August 16, 20222 yr 1 hour ago, DawPi said: Hm, load app info every page check isn't much efficient. Maybe someone else has better idea. But thanks for sharing it! For what it's worth, the current application and module is already loaded by the dispatcher (as mentioned by CodingJungle), so it won't reload it - it would just use the existing data already in memory. Additionally, applications and modules are cached in the data store so loading them on the fly should have very little effect on performance.