Note that there are some explanatory texts on larger screens.

plurals
  1. POCakephp load element with BBcode/shortcode
    text
    copied!<p>I am looking for input/help on how to do this. Might be some PHP/cake developers could provide some good solutions here. Cakephp 2.3 something :) </p> <p><strong>Problem;</strong> How to put shortcodes in wysiwyg editor (example: <strong>[slideshow=1]slideshow here[/slideshow]</strong>) and render an element (in this case, loading and displaying the slideshow with ID=1).</p> <p>ShortcodeHelper.php</p> <pre><code>App::import('Helper', 'Html', 'Router'); class ShortcodeHelper extends AppHelper { public $shortcodes = array( 'slideshow' =&gt; '/(\[slideshow=)(.+?)(\])(.+?)(\[\/slideshow\])/' ); public $returncodes = array( //'slideshow' =&gt; $this-&gt;render('/elements/slideshow', array('id'=&gt;'\\2')) 'slideshow' =&gt; '&lt;strong rel="\\2"&gt;\\4&lt;/strong&gt;' ); public function render($content, $render=null) { $shortcodes = $this-&gt;shortcodes; $returncodes = $this-&gt;returncodes; if(isset($render)) { $temp_shortcodes = array(); $temp_returncodes = array(); foreach ($render as $key =&gt; $value) { $temp_shortcodes[$key] = $shortcodes[$value]; $temp_returncodes[$key] = $returncodes[$value]; } $returncodes = $temp_returncodes; $shortcodes = $temp_shortcodes; } $return = preg_replace($shortcodes, $returncodes, $content); return $this-&gt;output($return); } } </code></pre> <p>view.ctp (call render function from helper, and run the page-content trough it):</p> <pre><code>&lt;?php echo $this-&gt;Shortcode-&gt;render($page['Page']['body']); ?&gt; </code></pre> <p>Thanks. You are awesome!! :) -Tom</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload