public function compile_to_html($template_config, $data) { $rows = $data[$template_config['content'] ? $template_config['content'] : 'rows']; $fields = $template_config['items']; $table_html = $this->table_template['table']; $trs_html = []; // 表头 $tds_html = []; foreach ($fields as $field_name => $field_config) { array_push($tds_html, $this->compile(['style' => $field_config['style'], 'class' => $field_config['class'], 'content' => $field_config['label'] ? $field_config['label'] : __(lcfirst(MODULE_NAME) . '.' . $field_name)], $this->table_templates['th'])); } array_push($trs_html, $this->compile(["style" => $template_config['thead_style'], "class" => $template_config['thead_class'], "content" => implode("", $tds_html)], $this->table_templates['tr'])); foreach ($rows as $k => $row) { $tds_html = []; foreach ($fields as $field_name => $field_config) { $content = $field_config['content'] ? Formater::spf($field_config['content'], $row) : $row[$field_name]; if ($field_config['format']) { $method = $field_config['format']; $content = Formater::$method($content); } array_push($tds_html, $this->compile(['style' => $field_config['style'], 'class' => $field_config['class'], 'content' => $content], $this->table_templates['td'])); } array_push($trs_html, $this->compile(["style" => $template_config['tr_style'], "class" => $template_config['tr_class'], "content" => implode("", $tds_html)], $this->table_templates['tr'])); } return $this->compile(["style" => $template_config['style'], "class" => $template_config['class'], "content" => implode("", $trs_html)], $this->table_templates['table']); }
public function compile_to_html($template_config, $data) { $content = $template_config['content']; if (is_string($template_config['content'])) { $content = Formater::spf($template_config['content'], $data); } return $this->compile(['style' => $template_config['style'], 'class' => $template_config['class'], 'content' => $content]); }
public function compile_to_html($template_config, $data) { $this->template = '<div style="%(style)s" class="float %(class)s">%(content)s</div>'; $htmls = []; foreach ($template_config['items'] as $item) { $content = $item['content']; if (is_string($item['content'])) { $content = Formater::spf($item['content'], $data); } array_push($htmls, $this->compile(['style' => $item['style'], 'class' => $item['class'], 'content' => $content])); } return sprintf("<div>%s<div class=\"clearfix\"></div></div>", implode("", $htmls)); }