Basecoat\View::replaceDataTags PHP Method

replaceDataTags() public method

Search and replace data tags in templates Allows usage of {{:data}} tags to output data instead of having to use
public replaceDataTags ( String &$tpl ) : String
$tpl String template text to search and replace data tags on
return String the processed template with data tags replaced
    public function replaceDataTags(&$tpl)
    {
        if (!$this->enable_data_tags) {
            return $tpl;
        }
        if (count($this->data) > 0) {
            // create tags
            $makeTags = function (&$tag, $key, $tag_wrap) {
                $tag = $tag_wrap['prefix'] . $tag . $tag_wrap['suffix'];
            };
            // Extract scalar variable
            $data_tags = array();
            foreach ($this->data as $k => $v) {
                if (is_scalar($v)) {
                    $data_tags[$k] = $v;
                }
            }
            $tag_keys = array_keys($data_tags);
            array_walk($tag_keys, $makeTags, $this->data_tags_delimiters);
            // search and replace data tags
            $tpl = str_replace($tag_keys, $data_tags, $tpl);
        }
        // cleanup any lingering tags
        //$this->stripDataTags($tpl);
        //$tpl = preg_replace('/{{:.[^}}]+}}/', '', $tpl);
        //return $tpl;
    }