How to use Markdown class in Yii

I see that there is a Markdown CMarkdown class, but how to use it?

There are no examples anywhere, and the methods are not self-evident.

Am I using it statically, like CHtml , or weird, like a widget?
Or do I need init this somewhere like a model?

+6
source share
2 answers

You can use CMarkdown as a widget in this form:

 $this->beginWidget('CMarkdown', array('purifyOutput'=>true)); echo $content; $this->endWidget(); 

When $ content contains Markdown syntax, it will be processed by widgets. The array contains values ​​for the public properties of CMarkdown. The properties are documented in the class reference .

CMarkdown is used in the Yii blog example and you will find it in this view file .

+7
source

This works and is the easiest:

 static function markdown( $str ) { $md = new CMarkdown; return $md->transform($str); } 

Static function in the parent controller. Probably not the Yii path, but it's simple:

 <?=self::markdown($post->body)?> 
+6
source

Source: https://habr.com/ru/post/886302/


All Articles