diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index fe827558d36..4efe670aafd 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -503,7 +503,7 @@ class help_icon implements renderable { * @package core * @category output */ -class pix_icon implements renderable { +class pix_icon implements renderable, templatable { /** * @var string The icon name @@ -545,6 +545,24 @@ class pix_icon implements renderable { unset($this->attributes['title']); } } + + /** + * Export this data so it can be used as the context for a mustache template. + * + * @param renderer_base $output Used to do a final render of any components that need to be rendered for export. + * @return array + */ + public function export_for_template(renderer_base $output) { + $attributes = $this->attributes; + $attributes['src'] = $output->pix_url($this->pix, $this->component); + $templatecontext = array(); + foreach ($attributes as $name => $value) { + $templatecontext[] = array('name' => $name, 'value' => $value); + } + $data = array('attributes' => $templatecontext); + + return $data; + } } /** diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 45f86b8ea96..ab26c4b656c 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2095,13 +2095,8 @@ class core_renderer extends renderer_base { * @return string HTML fragment */ protected function render_pix_icon(pix_icon $icon) { - $attributes = $icon->attributes; - $attributes['src'] = $this->pix_url($icon->pix, $icon->component); - $templatecontext = array(); - foreach ($attributes as $name => $value) { - $templatecontext[] = array('name' => $name, 'value' => $value); - } - return $this->render_from_template('core/pix_icon', array('attributes' => $templatecontext)); + $data = $icon->export_for_template($this); + return $this->render_from_template('core/pix_icon', $data); } /**