Question view class and template

A view class

Add a view class in the location [customization_folder]/views/question_customtype/view.html.php and use the class name ConfigboxViewQuestion_Customtype.

class ConfigboxViewQuestion_Customtype extends ConfigboxViewQuestion { function prepareTemplateVars() { parent:prepareTemplateVars(); } }

You can see class members in ConfigboxViewQuestion, these will all be available to you in the template. The parent class' prepareTemplateVars method sets all template variables, in the override you can add data.

A view template

Add a view template in the location [customization_folder]/views/question_customtype/tmpl/default.php

Important: Every question template needs to have the <div> wrapper with the attributes below.

<?php defined('CB_VALID_ENTRY') or die(); /** @var $this ConfigboxViewQuestion_Customtype */ ?> <div id="<?php echo hsc($this->questionCssId);?>" class="<?php echo hsc($this->questionCssClasses);?>" <?php echo $this->questionDataAttributes;?>> </div>

Within the template and this wrapper, you add HTML and question data as needed. You can compare the template with the ones of the built-in question types in [application_dir]/views/question_*


Use the function hsc() to escape variable output. It is a shortcut to htmlspecialchars($string, ENT_QUOTES).

Notable view variables

$this->selection (string)

Holds the value of the last selection that the user has made. See this article (Heading configbox/configurator.sendSelectionToServer) on how to send user’s selections to the CB backend.

$this->outputValue (string)

Holds the user readable string of the selection. In case your type uses predefined answers, it’ll be the answer’s title, otherwise simply the selection.

$this->question (ConfigboxQuestion)

Holds all data of the question. See PHP doc for all object members of ConfigboxQuestion.

$this->question->answers (ConfigboxAnswer[])

If your question type has answers, this will be an array of ConfigboxAnswer objects. See PHP doc in your IDE for all object members.