Witam !
Mam problem, zagwostkę czemu zmiany nie ulega to co jest pogrubione lecz tylko główna część {% loop:user|users %}
Tak są przechowywane dane
$this->variable = array('users' => array('users_login' => 'aaa', 'users_login' => 'bbb'); $this->variable = array('friends' => array('users_login' => 'bbb', 'users_friend' => 'aaa');
Szablon HTML
<div class="users_item_list"> {% loop:user|users %}
{% loop:friend|friends %}
{friend|users_friend}
{% endif %}
{% endloop %}
Do $this->template jest wczytany szablon
if(preg_match_all("/{% loop:(.*)[\|](.*) %}\s(.+)\s{% endloop %}/Us", $this->template, $matches)) { for($i=0; $i < count($matches[0
]); $i++) {
$loopVariable = $matches[1][$i];
$arrayVariable = $matches[2][$i];
$loopContent = $matches[3][$i];
$result = "";
if(isset($this->variable[$arrayVariable]) && is_array($this->variable[$arrayVariable])) { foreach($this->variable[$arrayVariable] as $name) {
$this->loops[$loopVariable] = $name;
$result .= $this->replaceVariable($loopContent);
}
}
$this->template = str_replace($matches[0
][$i], $result, $this->template); }
}
private function replaceVariable($loopContent) {
for($i=0; $i < count($matches[0
]); $i++) { if(isset($this->loops[$matches[1
][$i]]) && is_array($this->loops[$matches[1
][$i]])) { foreach($this->loops[$matches[1][$i]] as $name => $value) {
$loopContent = str_replace("{".$matches[1
][$i]."|".$name."}", $value, $loopContent); }
}
return $loopContent;
}
}
}