I used widget like this
<?php $this->beginWidget('path.to.WidgetClass'); ?>
...body content that may be captured by the widget...
<?php $this->endWidget(); ?>
Which method can capture body content? I use init() and run() to show begin and end widget.
You can use ob buffer to capture the body content.
Alternatively, you can extend COutputProcessor. You may refer to CMarkdown on how to extend COutputProcessor.
And to conditionally display content in widget I have to use these methods?