Meddysong Posted July 12, 2017 Posted July 12, 2017 I have a custom block in Pages which shows the latest records for a particular category. Unfortunately, if you drag and drop, that block features on every page that the database appears on; category view, display and listing. That's not what I want. There's no point having it on listing or the record display. I know of one solution and its working: {{if \IPS\Request::i()->path == 'holidays'}}{block="our_latest_adventures"}{{endif}} That adds the block to my category listing (which is found at http://timeofftakeoff.com/holidays/). What I'd like to do is add it a step deeper to my categories mysite.com/holidays/2011, mysite.com/holidays/2012 etc. Obviously I could write it as {{if \IPS\Request::i()->path == 'holidays' || \IPS\Request::i()->path == 'holidays/2012' || \IPS\Request::i()->path == 'holidays/2013'}}{block="our_latest_adventures"}{{endif}} and so on but that's going to get quite lengthy and it's triggering me because there must be a neater solution. Can anybody think of a way to rewrite it such that in one statement we get 'holidays/%' but not 'holidays/%/xyz'? By that I mean anything which goes one level past 'holidays' but doesn't include anything which goes further. (So, http://timeofftakeoff.com/holidays/2014/ is OK but http://timeofftakeoff.com/holidays/2014/spain-2014/ and http://timeofftakeoff.com/holidays/2014/spain-2014/day-9-madrid/ aren't.) Does anybody have any thoughts?
newbie LAC Posted July 13, 2017 Posted July 13, 2017 You can explode the path var and check count of elements {{$pieces = explode('/', \IPS\Request::i()->path);}} {{if $pieces[0] == 'holidays' and count($pieces) <= 2}}{block="our_latest_adventures"}{{endif}}
Meddysong Posted July 13, 2017 Author Posted July 13, 2017 Clever man - thank you! There's an additional problem that I've only just realised: I would like this block to appear in the sidebar. If I paste this code into the page or into the database template, it will appear as part of the article body but not in the side bar. Is there a clever solution for that?
newbie LAC Posted July 13, 2017 Posted July 13, 2017 Why you don't use Manager blocks? 2 hours ago, Meddysong said: If I paste this code into the page Try add {{$pieces = explode('/', \IPS\Request::i()->path);}} {{if $pieces[0] == 'holidays' and count($pieces) <= 2}} {{\IPS\Output::i()->sidebar['contextual'] = \IPS\cms\Blocks\Block::display('our_latest_adventures');}} {{endif}}
Meddysong Posted July 13, 2017 Author Posted July 13, 2017 You're a genius - thank you! There's just one final problem: the block is displaying as though it's a horizontal one although it's in the sidebar: http://timeofftakeoff.com/holidays/2016/ Do I need to add a parameter somewhere to force it to be vertical? If so, how and where? Thanks again!
newbie LAC Posted July 13, 2017 Posted July 13, 2017 17 minutes ago, Meddysong said: Do I need to add a parameter somewhere to force it to be vertical? If so, how and where? \IPS\cms\Blocks\Block::display('our_latest_adventures', 'vertical')
Meddysong Posted July 13, 2017 Author Posted July 13, 2017 It's easy when you know how The final problem is that it doesn't have any of the formatting (ie for the section title) that the usual widgets have. Is that too much to hope for. (It's not the end of the world if it is. At least I have the data!)
Meddysong Posted July 13, 2017 Author Posted July 13, 2017 Bah ... and now I'm confused why the vertical display works correctly on pages like this one http://timeofftakeoff.com/holidays/2014/ (even if the formatting isn't there) but not on this one http://timeofftakeoff.com/holidays/
newbie LAC Posted July 15, 2017 Posted July 15, 2017 On 13.07.2017 at 6:40 PM, Meddysong said: The final problem is that it doesn't have any of the formatting (ie for the section title) that the usual widgets have. Is that too much to hope for. (It's not the end of the world if it is. At least I have the data!) Widgets and contextual menu have different markup Try {{$block = null; try {$block = \IPS\cms\Blocks\Block::load('our_latest_adventures', 'block_key');} catch(\Exception $e) {} }} {{if $block and \IPS\cms\Blocks\Block::display($block, 'vertical')}} {{\IPS\Output::i()->sidebar['widgets']['sidebar'][] = $block->widget();}} {{endif}}
Recommended Posts
Archived
This topic is now archived and is closed to further replies.