Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted March 11, 20168 yr I've created a block that shows popular records for a certain database. Now I want that block to NOT display when the user is viewing a record. So I would like to add logic that hides the block if we are on a record page. Usually, I would just use the dispatcher like this: {{$dispatcher = \IPS\cms\Databases\Dispatcher::i();}} {{if !$dispatcher->recordId}} {{/* block content here */}} {{endif}} The problem is that the dispatcher does not reflect the page the user is currently seeing. On a page were a user sees a record, the a dump of the dispatcher from within the block looks like this: Object(IPS\cms\Databases\Dispatcher)#106 (9) { ["controllerLocation"]=> string(5) "front" ["databaseId"]=> int(6) ["categoryId"]=> NULL ["recordId"]=> NULL ["url"]=> NULL ["module"]=> NULL ["output"]=> NULL ["classname":protected]=> NULL ["dispatcherController"]=> NULL } One would expect the category and record id to be set, but they aren't. Also, calling \IPS\Request::i() isn't much use: object(IPS\Request)#4 (3) { ["cookie"]=> array(7) { ["IPSSessionFront"]=> string(32) "1234567890123456789012345678901" ["IPSSessionAdmin"]=> string(32) "1234567890123456789012345678901" ["acpTabs"]=> string(93) "{"core":[],"community":[],"members":[],"nexus":[],"content":[],"stats":[],"customization":[]}" ["hasJS"]=> string(4) "true" ["member_id"]=> string(1) "1" ["pass_hash"]=> string(32) "fc725df66df9a155b5d1b5079071781f" ["ipsTimezone"]=> string(19) "Africa/Johannesburg" } ["_url":protected]=> object(IPS\Http\Url)#6 (5) { ["url":protected]=> string(201) "http://mysite.com/index.php?app=cms&module=pages&controller=builder&do=getBlock&blockID=app_cms_Blocks_acbupkzwu&pageID=5&orientation=vertical&csrfKey=1234567890123456789012345678901" ["data"]=> array(4) { ["scheme"]=> string(4) "http" ["host"]=> string(28) "mysite.com" ["path"]=> string(10) "/index.php" ["query"]=> string(155) "app=cms&module=pages&controller=builder&do=getBlock&blockID=app_cms_Blocks_acbupkzwu&pageID=5&orientation=vertical&csrfKey=1234567890123456789012345678901" } ["queryString"]=> array(8) { ["app"]=> string(3) "cms" ["module"]=> string(5) "pages" ["controller"]=> string(7) "builder" ["do"]=> string(8) "getBlock" ["blockID"]=> string(24) "app_cms_Blocks_acbupkzwu" ["pageID"]=> string(1) "5" ["orientation"]=> string(8) "vertical" ["csrfKey"]=> string(32) "1234567890123456789012345678901" } ["isInternal"]=> bool(true) ["isFriendly"]=> bool(false) } ["data":protected]=> array(8) { ["app"]=> string(3) "cms" ["module"]=> string(5) "pages" ["controller"]=> string(7) "builder" ["do"]=> string(8) "getBlock" ["blockID"]=> string(24) "app_cms_Blocks_acbupkzwu" ["pageID"]=> string(1) "5" ["orientation"]=> string(8) "vertical" ["csrfKey"]=> string(32) "1234567890123456789012345678901" } } Any way to get the correct dispatcher/request object?
March 14, 20168 yr Author Anybody? I basically just need to be able to determine if I'm on record or category level.
May 12, 20168 yr Also looking for how to achieve differentiating between category levels in widgets since the Dispatcher doesn't work as it does on templates to achieve this.
Archived
This topic is now archived and is closed to further replies.