We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Rendering snippets/embeds within an extension to make output visible when editing channel data

Development and Programming

onewed's avatar
onewed
13 posts
14 years ago
onewed's avatar onewed

When rendering channel data for editing I’d like to select a token in the data and replace it with the rendered result of an embed or snippet. Is this possible? The goal here is to allow authors to use CKEditor buttons to add content easily (like cross-channel elements) without having to learn the EE tag syntax.

Pseudo-code using the hook I plan on using.

function publish_form_entry_data($entry_data)
{
  $modified_field = preg_replace('#==my token==#',
                                  $this->EE->render_snippet('my_snippet_name'), // <-- method I don't know
                                  $entry_data['field_id_3'] 
                                 );

  $entry_data['field_id_3'] = $modified_field;
  return $entry_data;
}
       
onewed's avatar
onewed
13 posts
14 years ago
onewed's avatar onewed

I figured out how to create an instance of the template renderer. However I found that it is not converting a snippet into the html I want. As a workaround I used an {embed}.

Pseudo code to render my placeholder as an embed.

function publish_form_entry_data($entry_data)
   {
      $this->EE->load->library('template', NULL, 'TMPL');

      $data = $entry_data['field_id_3'];

      $matches = array();
      $num = preg_match_all('#{placeholder entry_id="([\\d]+)"}#', $data, $matches, PREG_SET_ORDER);

      if($num)
      {
         foreach($matches as $match)
         {
            $tmp = '{embed="images/edit_placeholder" the_id="' . $match[1] . '"}';
            $this->EE->TMPL->parse($tmp);

            $data = str_replace($match[0], trim($tmp), $data);
         }
      }

      $entry_data['field_id_3'] = $data;
      return $entry_data;
   }
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.