MODX Cloud

The Most Productive MODX Learning Playground Ever

Claim Free Lab Account

Adding a Custom TV Type - MODX 2.2

Version 1 by Shaun McCormick
on Apr 20, 2012 09:29.

compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (4)

View Page History
These event handlers tell MODX to check these directories for our TV files when doing all the rendering and processing. Think of it like adding library or include paths.

{note}The pathing plugin will not be required in MODX 2.3; the Namespace will handle all the pathing. This is why we told you earlier to make the Namespace. :){note}

h2. Creating the Input Controller

The input controller is what actually loads the markup for the custom TV input. Create the input controller file here:

{quote}core/components/ourtvs/tv/input/templateselect.class.php{quote}

And inside, you can put this code:
Now you can see here we are specifying a "tpl" file for rendering our TV. Go ahead and put it here:

{quote}core/components/ourtvs/tv/input/tpl/templateselect.tpl{quote}

And make its content:
!ctv1.png!

h2. Creating the Output Controller

Okay, so now we want to make the output controller, let's create the file at:

{quote}core/components/ourtvs/tv/output/templateselect.class.php{quote}

And the content:

{code}
class TemplateSelectOutputRender extends modTemplateVarOutputRender {
public function process($value,array $params = array()) {
return '<div class="template">'.$value.'</div>';
}
}
return 'TemplateSelectOutputRender';
{code}

There we go - now when we render this in the front-end, it will display the ID of our selected Template wrapped in a div.

h2. See Also