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;
}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;
}Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.