Skip to content

Instantly share code, notes, and snippets.

@jneubauer
Last active August 29, 2015 14:25
Show Gist options
  • Save jneubauer/70a0709d78426d8d814a to your computer and use it in GitHub Desktop.
Save jneubauer/70a0709d78426d8d814a to your computer and use it in GitHub Desktop.
Front End Editing Override
<!-- this goes in the template override(e.g., /templates/your-template/html/com_content/form/edit.php) -->
<!-- Instead of just this -->
<?php echo $this->form->renderField('field_name', 'attribs'); ?> <!-- displays a field already in the XML file -->
<!-- You need this -->
<!-- this part can be added anywhere in the file - preferrable towards the beginning, but definitely before the next part -->
<?php if ($this->item->id) : ?> <!-- checking if this is an existing article or not -->
<?php $attribs = json_decode($this->item->attribs); ?> <!-- if it is an existing article, get the attribs part of the existing record (attribs is where we save custom fields). You only need this line once. -->
<?php echo $this->form->setValue('field_name', 'attribs', $attribs->field_name); ?> <!-- set the value of the custom field to what is already saved. Duplicate for the number of fields you need, changing the field_name as needed. -->
<?php endif; ?>
<!-- this part needs added to the file right where you want to display it. So, if you want it to show right after the description field, find the description field and place this right after it. Duplicate for the number of fields you need, changing the field_name as needed.-->
<?php echo $this->form->renderField('field_name', 'attribs'); ?> <!-- now we display the field. If we are editing an existing article, the previously saved data will be populated already -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment