Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

[SOLVED] Render category description to side panel

Rardor81Rardor81 New
edited March 2011 in Vanilla 2.0 - 2.8
I'm trying to display category descriptions in my side panel. The technique described in another post works great, but not in the panel.

So, a php noob, I ventured out to create my own plugin. I'm still not having a ton of luck, though-- I can successfully display category descriptions-- but they're either BEFORE or AFTER the entire content of my forum (depending on how I render it).

I have two functions, GetData and ToString. When I use an echo statement in GetData, the category description renders out successfully (but again, only at the very top or very bottom of the page).

When I use an echo statement in ToString, I can render simple text out to the side panel. SO CLOSE! But I can't, for the life of me, figure out how to render any variables to the side panel (like $Sender->Category->Description). The same echo statement that renders out the description in GetData doesn't do so in ToString.

So I guess what I'm asking is, how do I get the category description to render out in the side panel? I'm guessing I need to do it using ToString. Hopefully I'm just making some trivial php syntax mistake. Any help is much appreciated!

So here's what I've got so far, which renders the description out to the top or bottom of the page, but not the side panel:

default.php
class CategoryInfoPlugin extends Gdn_Plugin {

public function CategoriesController_Render_Before($Sender) {
include_once(PATH_PLUGINS.DS.'CategoryInfo'.DS.'class.categoryinfomodule.php');
$CategoryInfoModule = new CategoryInfoModule($Sender);
$CategoryInfoModule->GetData($Sender->Category->Description);
$Sender->AddModule($CategoryInfoModule);
}

public function Setup() {
// No setup required
}
}
class.categoryinfomodule.php
class CategoryInfoModule extends Gdn_Module {
public function AssetTarget() {
return 'Panel';
}
public function GetData($Sender) {
echo $Sender; // This displays, but not in the side panel
}
public function ToString() {
echo $Sender; // This doesnt display anything - why!? so cruel
echo 'Hello world!'; // This displays simple text in the side panel
}
}

Comments

  • Options
    Hello,

    let's start from class.categoryinfomodule.php. In CategoryInfoModule::ToString() method, $Sender is an object so echo is not a good idea to debug that variable. Use var_dump.
    Then that variable is not accessible from ToString method; you can you $this->_Sender to access to $Sender object that is assigned when you construct CategoryInfoModule instance in CategoriesController_Render_Before inside default.php.
    Also ToString method must return a string, not echo it.
    class CategoryInfoModule extends Gdn_Module {
    public function AssetTarget() {
    return 'Panel';
    }
    public function GetData($Sender) {
    echo $this->_Sender->Category->Description;
    }
    public function ToString() {
    var_dump($this->_Sender);
    return 'Hello world!';
    }
    }
    If you want to display a more complicated text, then it is better to create a view for that module.
  • Options
    Thank you @netcelli_ !!

    That's just the help I needed! It works great now. Here's the working code for others who may be interested:
    class CategoryInfoModule extends Gdn_Module {
    public function AssetTarget() {
    return 'Panel';
    }
    public function GetData($Sender) {
    return;
    }
    public function ToString() {
    return $this->_Sender->Category->Description;
    }
    }
Sign In or Register to comment.