virap1 Posted March 15 Share Posted March 15 I have database articles with categories. I created a block that needs to be obtain the current category id for a given database record being displayed. I tried this and number of other things but still unable to get the category id. {{$cat_id=$category->database_id;}} Does anyone know how to do it? Thanks. Link to comment Share on other sites More sharing options...
Nathan Explosion Posted March 15 Share Posted March 15 (edited) $record->container()->id Edited March 15 by Nathan Explosion Link to comment Share on other sites More sharing options...
virap1 Posted March 15 Author Share Posted March 15 @Nathan Explosion thank you. Adding this {{$cat_id = $record->container()->id;}} results 503 error message in pages Link to comment Share on other sites More sharing options...
Nathan Explosion Posted March 15 Share Posted March 15 (edited) 6 minutes ago, virap1 said: in pages Where exactly are you adding this in pages? You've given no information about what template you are editing so I'm assuming that it is the record display template in the Pages templates that you are editing, as you mentioned: 1 hour ago, virap1 said: a given database record Give more information than you are currently providing...help people help you. Describe what you are doing more... 1 hour ago, virap1 said: created a block What is the full code of the block? Where is the block placed in Pages? etc. Edited March 15 by Nathan Explosion Link to comment Share on other sites More sharing options...
virap1 Posted March 15 Author Share Posted March 15 That is intended to be used inside a custom html block that will display content based on the category id of a given database record. Link to comment Share on other sites More sharing options...
sound Posted March 15 Share Posted March 15 (edited) try it the other way around have the category conditional call on the record template with a separate block for each category as needed Edited March 15 by sound Link to comment Share on other sites More sharing options...
virap1 Posted March 15 Author Share Posted March 15 (edited) Sound, thank you but I am not sure I understood. 49 minutes ago, Nathan Explosion said: What is the full code of the block? Where is the block placed in Pages? etc. @Nathan Explosion Here is the full code where cat_id should be the current article (database record) category id {{if request.app == 'cms' }} {block="articles_related_articles_{$cat_id}"} {{endif}} Edited March 15 by virap1 Link to comment Share on other sites More sharing options...
Solution Nathan Explosion Posted March 15 Solution Share Posted March 15 This post was recognized by Marc Stridgen! Nathan Explosion was awarded the badge 'Helpful' and 5 points. OK - assumptions made: You are creating a custom manual HTML block that contains that code You are placing that block in the sidebar when viewing a record {{if request.app == 'cms' }} {{$databaseId = \IPS\cms\Databases\Dispatcher::i()->databaseId;}} {{$class = "\IPS\cms\Records".$databaseId;}} {{$record = $class::load(\IPS\Request::i()->id);}} {{$categoryId = $record->container()->id;}} {block="articles_related_articles_{$categoryId}"} {{endif}} If that doesn't work (and there is probably a better way of doing it, this was a quick throw-togehter) then I've got no idea where you are putting it. Link to comment Share on other sites More sharing options...
virap1 Posted March 15 Author Share Posted March 15 @Nathan Explosion thank you very much. Your suggestion works as expected. Link to comment Share on other sites More sharing options...
Recommended Posts