2016-03-24 10 views
1

ショートコードをWYSIWYGに追加しようとしています。私はthis libraryを使用しています。私はaccordion from bootstrapにこれを解析しようとしています:thunderer/shortcodeを使用してショートコードを解析しようとしています

[panel] 
[header] 
Heading goes here 
[/header] 
[content] Content goes here [/content] 

[header] 
Heading goes here 
[/header] 
[content] Content goes here [/content] 
[/panel] 

私のコードは次のようになります。

use Thunder\Shortcode\HandlerContainer\HandlerContainer; 
use Thunder\Shortcode\Parser\RegularParser; 
use Thunder\Shortcode\Processor\Processor; 
use Thunder\Shortcode\Shortcode\ShortcodeInterface; 

function processAgendaContent($content) 
{ 

    $handlers = new HandlerContainer(); 
    $handlers->add('panel', function(ShortcodeInterface $s) { 
     return "<div class=\"panel panel-default\">"; 
    }); 

    $handlers->add('header', function(ShortcodeInterface $s) { 
     return ' 
    <h4 class="panel-title"> 
    <a href="#collapse1" target="_blank" role="button" data-toggle="collapse" aria-expanded="true" aria-controls="collapse1" class="btn-collapse"> 
    ' . $s->getContent() . '</a> 
    </h4>'; 

    }); 

    $processor = new Processor(new RegularParser(), $handlers); 

    echo $processor->process($content); 

私の問題は、今私が解析しようとしているとき、それは開始タグを解析することであるが、終了タグではないので、getContent()が機能しないという理由で想像しています。どのようなアイデアを私は間違って何ですか?ありがとう

答えて

1

私はショートコードライブラリの著者です。あなたの問題を解決するには、あなたのpanelショートハンドラ本体を変更してください:

return '<div class="panel panel-default">'.$s->getContent().'</div>'; 

すべてのショート・ハンドラは、全ショートテキストから返されるものを制御します。単純な文字列を返しただけで、内容をどこにも含めなかったので、[panel]でカプセル化されたテキスト全体が破棄されました。

このライブラリがどのように機能するかを理解するのに役立つことを願っています。ご質問がありましたら、ここで喜んでお答えします。

+1

驚くばかりの図書館の男! – raygo

関連する問題