How to change HTML generated by module
All modules generate their HTML through their own template class that is described in template.php file. It is not controlled by CMS. So some modules may not follow this rule.
If you wish to override template in folder: ip_cms/modules/administrator/search/template.php, you need to copy this template.php file to directory: ip_themes/your_template/modules/administrator/search/template.php and change required html parts.
NOTE: Don't modify original template files because they will be overwritten on update!
NOTE: This method also works on widget templates.
Customize form layout
Most of the forms are generated using standard form generation class. In this case template file will not represent HTML you want to change. The form will be generated using code simmilar to this:
$standardForm = new \Library\Php\Form\Standard($fields);
return $standardForm->generateForm($parametersMod->getValue('community', 'user', 'translations', 'button_register'), $site->generateUrl());
To change form layout you need to do two things:
- Duplicate standard form template class and modify it to your needs
- Override template file to use your form layout class instead default
Create your own form template class
To create your own form template class, duplicate default one from ip_libs/php/form/templates/standard.php to ip_thems/ip_default/any_folder_you_like folder.
This file contains functions that generates form. Modify them as you like.
Use your custom template class instead of default
In template file, where required form is generated, replace line like this:
$standardForm = new \Library\Php\Form\Standard($fields);
to these lines:
require_once('yourDuplicatedAndModifiedTemplateClass.php');
$templateObject = new \Library\Php\Form\Templates\MyFormTemplate();
$html_form = new \Library\Php\Form\Standard($fields, $templateObject);
As you can see, last method is the same, except last paramter. We suply our custom object to the form constructor. Keep in mind, that you need to do these changes in overriden template file as it is described above. Don't change original system files as they will be replaced on update.
Download and examine example that modifies default contact form template and adds text "MY CUSTOM TEXT" above all contact form widgets.
Write a comment
You must be logged in to comment.