What is this article for

You will learn how to create and use your own HTML page outputs using CB and get a solid understanding of CB's built-in output for customizations.

For this article you must be familiar with the MVC development pattern. If you're not, best learn the basics of MVC using proper literature or resources on the web before going further.

Concept

A KenedoView is part of Kenedo's MVC pattern. 

KenedoViews have two specific distinction from a classic MVC View:

Example of rendering a view:

// Gets you an instance of the View
$view = KenedoView::getView('ConfigboxViewCart');

// Returns the view's output
$output = $view->getHtml();

Files and their locations

Example

Assume a view called 'example' in the customization folder:

{customization folder}/views/example/view.html.php
{customization folder}/views/example/tmpl/default.php

What does the view class do?

Setting template variables for the template file

Recommended way is to override the method KenedoView::prepareTemplateVars() and setting values to class variables.

Example

Assume a view called 'example'. File location {customization folder}/views/example/view.html.php

class ConfigboxViewExample extends KenedoView {
	
	/**
	* @var string[] 
	*/
	var $dataForMyTemplate;


	function prepareTemplateVars() {
		$this->dataForMyTemplate = array('so', 'much', 'to', 'show');
	}

}

(template file in {customization folder}/views/example/tmpl/default.php)

/** @var ConfigboxViewExample $this */
var_dump($this->dataForMyTemplate);

At this point you can use your view to output something to page. Best practice is to create a custom controller as well, but you skip that

On Joomla using a controller and direct URL:

First you create a controller for that view. A controller takes in query string variables and handles the requested task.

Each controller class extends KenedoController and must implement 4 abstract methods (dealing with the default view and model it uses).

Location of controller files: {customization folder}/controllers/{controller name}.php (in our example 'example.php')

class ConfigboxControllerExample extends KenedoController {
	
	/**
 	* @return NULL
 	*/
	protected function getDefaultModel() {
		return NULL;
	}


	/**
	 * @return ConfigboxViewExample
	 */
	protected function getDefaultView() {
		return KenedoView::getView('ConfigboxViewExample');
	}


	/**
	 * @return NULL
	 */
	protected function getDefaultViewList() {
		return NULL;
	}

	/**
	 * @return NULL
	 */
	protected function getDefaultViewForm() {
		return NULL;
	}

}

(controller file in {customization folder}/controllers/example.php)

Once you have this controller file in place, use your browser or HTTP client with this URL

index.php?option=com_configbox&controller=example&task=display

On Joomla using a menu item

Once you have your view files in place, go to Joomla's menu manager and add a menu item, as 'menu item type' selectConfigbox → Custom and then enter the View Name (in our example, use 'example') in the menu item's form. Then you navigate to the menu item's URL and you will see the view's output.

On Wordpress using a short code handler

This part assumes you know how to create a short code handler. Be sure to refer to Wordpress literature or web resources to take advantage of this

In the short code handler you get an instance of your view and return the return value of the view's getHtml() function.

$view = KenedoView::getView('ConfigboxViewExample');
return $view->getHtml();

Load custom stylesheets

KenedoViews control which style sheets the platform will load. Mind that CB loads a stylesheet for customizations on any page that shows a KenedoView - depending on your use-case you can add another.

Determining which stylesheets to load is up to the KenedoViews rendered on the page. To control this, you override the method getStyleSheetUrls(). This method returns the full URLs to the stylesheets needed for this view (and this view only).

Example for having a stylesheet from the customization assets folder loaded:

class ConfigboxControllerExample extends KenedoController {
  ...
  /**
  * @return string[] Array of full URLs to the stylesheets you need loaded
  */
  function getStyleSheetUrls() {
	$urls = parent::getStyleSheetUrls();
	$urls[] = KenedoPlatform::p()->getUrlCustomizationAssets().'/css/custom_stylesheet.css';
	return $urls;
  }
  ...  
}

Notes:

Load JS modules and execute init functions

KenedoView’s also control which JS to load. It is done by using AMD modules, managed by require.js. Learn how to take advantage of this in this article.