I am trying to develop an extension to add a field into the publish entry page. I would like this to be added directly after the url_title field. Using the show_full_control_panel_end hook, I would like to perform a preg_match_all to find:
<div class="itemWrapper">
<div class="itemTitle"><label for="url_title">URL Title</label></div>
<input dir="ltr" style="width: 100%;" name="url_title" id="url_title" value="woodscrews" size="20" maxlength="75" class="input" type="text">
</div>
and add some html to the end of it.
the regex I currently have, as a starter, is:
$look_for = "/<div class='itemWrapper'[^>]*>[\s]*<div class='itemTitle'[^>]*>(.*)<\/div>(.*)<\/div>/";
Im no good at regex - I could do this very easily with jQuery, but would like to stick with a non-js solution.
Any help appreciated.
Hi vinci,
Is this a custom field type you’re creating? If so, I can heartily recommend Brandon Kelly’s FieldFrame extension, which does all the Regex heavy lifting for you.
That said, if you’re looking to insert something inside the itemWrapper div, after the url_title field, the following should be headed in the right direction. Please be aware that I haven’t had a chance to try this, so it may not be bang on the money yet, or particularly efficient for that matter.
Caveats dispensed with, here you go:
$old_content = '<div class="itemWrapper"> etc. etc. </div>';
$replacement_content = "${1}${2}${3}This will be inserted inside the itemWrapper div, after the url_title field.${5}${6}";
$new_content = preg_replace('/^(.*)(name="url_title")(.*?)>(.*?)(<\/div>)(.*)$/i', $replacement_content, $old_content);
Hope that helps.
Stephen
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.