The actual rendering of the View when using the Cake Toolkit does not take place until the object model has been built. This occurs once the build() method of the View has completed. The rendering process is then determined by the renderer which has been set for the View. From the CtkView class you can set the renderer using the $renderer property, or at runtime via the setRenderer() method.
The plugin provides 2 renderers to use for your Views. By default, the Ctk.Web renderer is used in all CTK based Views. However, a Ctk.Schema renderer is also provided, to help visualize the object model which is built internally. See the Debugging documentation for more details.
A renderer extends the CtkRenderer class, which has an abstract setup() method, serving as the renderer's constructor. This initializes the necessary assets and configurations required for it's usage with the objects it renders. From this method it's possible to reach the View using the getView() method, which returns the current CtkView object.
Additionally, the class has another abstract method, render(), which is called for every object being rendered. It's important to note that the renderer is called for scope of an individual object, and not for the whole View at once. The name of the template file for the object being rendered can be accessed with the getTemplate() method of the object. To resolve the full path of a template you could use the following:
// determine if the factory is from a plugin
$plugin = $object->getFactory()->getPlugin();
// resolve the base path to use
$path = (!empty($plugin))? APP . 'Plugin' . DS . $plugin . DS . 'View' : dirname(__DIR__);
// compose the full path to the template file
$template = $path . DS . 'Factory' . DS . $object->getFactory()->getName() . DS . 'Templates' . DS . $object->getTemplate() . '.ctp';
The path for the template is not automatically resolved in order to allow templates to be used from any location. However, once the path has been determined, the template() method on the object can parse the template for that object, using $this as the scope of the object from the template file. This will return the static content generated by the object's template as a string.
Sometimes you may also want to control if the renderer has already been loaded previously. This can be an issue if using the factory in a View, as well as in a layout with the Factory helper. To check whether the renderer has been loaded before you can call the isLoaded() method, which returns a boolean which determines the loaded state.