I want to use template variables in the CMS. The same way UserDefinedForms allows you to place $UserDefinedForm in the Content HTML editor field.
This may have been covered but I cant find the correct example.
I want to be able to add a new tab to my page such as "My Custom Code" and the information on this tab to then be placed at the users choice in their content using $MyCustomCode.
I would also like to do this with any extra fields I create in the Site Config.
I found this code in the UserDefinedForms but not sure how to translate it to my situation, or if this is all you need etc.
/**
* Using $UserDefinedForm in the Content area of the page shows
* where the form should be rendered into. If it does not exist
* then default back to $Form.
*
* @return array
*/
public function index() {
if($this->Content && $form = $this->Form()) {
$hasLocation = stristr($this->Content, '$UserDefinedForm');
if($hasLocation) {
$content = str_ireplace('$UserDefinedForm', $form->forTemplate(), $this->Content);
return array(
'Content' => DBField::create_field('HTMLText', $content),
'Form' => ""
);
}
}
return array(
'Content' => DBField::create_field('HTMLText', $this->Content),
'Form' => $this->Form()
);
}
thanks