19 declare(strict_types=1);
21 require_once __DIR__ .
'/../lib/html-it/IT.php';
22 require_once __DIR__ .
'/../lib/html-it/ITX.php';
72 string $in_module =
"",
75 bool $a_use_cache =
true 78 $this->il_use_cache = $a_use_cache;
79 $this->il_cur_key = $file .
"/" . $in_module;
82 if (!file_exists($fname)) {
83 throw new ilTemplateException(
"Template '$fname' was not found.\nfile: " . $file .
"\nmodule: " . $in_module);
86 $this->tplName = basename($fname);
87 $this->tplPath = dirname($fname);
97 protected function init(): void
103 if ($this->il_use_cache &&
104 isset(self::$il_cache[$this->il_cur_key]) &&
105 is_array(self::$il_cache[$this->il_cur_key])
109 $this->flagBlocktrouble = self::$il_cache[
$this->il_cur_key][
"flagBlocktrouble"];
120 if ($this->il_use_cache) {
132 $this->
template =
'';
140 isset($this->blockvariables[
"content"][$a_blockname]) ||
141 isset($this->blockvariables[$a_blockname]);
149 $component_factory = $DIC[
"component.factory"];
150 foreach ($component_factory->getActivePluginsInSlot(
"uihk") as $ui_plugin) {
151 $gui_class = $ui_plugin->getUIClassInstance();
152 $resp = $gui_class->getHTML(
156 "tpl_id" => $this->tplIdentifier,
163 $html = $gui_class->modifyHTML($html,
$resp);
177 $part = self::IT_DEFAULT_BLOCK;
190 $part = self::IT_DEFAULT_BLOCK;
193 $this->activeBlock = $part;
194 return parent::setCurrentBlock($part);
207 return parent::touchBlock($block);
219 $this->activeBlock = self::IT_DEFAULT_BLOCK;
221 return parent::parseCurrentBlock();
224 public function addBlockFile(
string $var,
string $block,
string $tplname, ?
string $in_module =
null): bool
229 if (file_exists($tplfile) ===
false) {
230 echo
"<br/>Template '" . $tplfile .
"' doesn't exist! aborting...";
236 $component_factory = $DIC[
"component.factory"];
237 foreach ($component_factory->getActivePluginsInSlot(
"uihk") as $ui_plugin) {
238 $gui_class = $ui_plugin->getUIClassInstance();
239 $resp = $gui_class->getHTML(
264 foreach ($this->vars as $key => $val) {
265 if (is_array($this->blockvariables[$this->activeBlock]) &&
266 array_key_exists($key, $this->blockvariables[$this->activeBlock])
284 if (!$this->flagCacheTemplatefile ||
285 $this->lastTemplatefile !== $filename
291 $component_factory = $DIC[
"component.factory"];
292 foreach ($component_factory->getActivePluginsInSlot(
"uihk") as $ui_plugin) {
293 $gui_class = $ui_plugin->getUIClassInstance();
294 $resp = $gui_class->getHTML(
298 "tpl_id" => $this->tplIdentifier,
332 return file_exists($path);
338 protected function getTemplatePath(
string $a_tplname,
string $a_in_module =
''): string
340 $ilias_root = realpath(__DIR__ .
'/../../../../') .
'/';
342 if (str_starts_with($a_in_module, $ilias_root)) {
343 $a_in_module = str_replace($ilias_root,
'', $a_in_module);
346 if (str_ends_with($a_in_module,
'/')) {
347 $a_in_module = rtrim($a_in_module,
'/');
350 $tpl_sub_path =
'/templates/default/';
351 if (str_starts_with($a_tplname,
'components/ILIAS/UI/')) {
352 $a_in_module =
'components/ILIAS/UI/src';
353 $a_tplname = str_replace(
'components/ILIAS/UI/src/templates/default/',
'', $a_tplname);
356 if (str_starts_with($a_tplname, $ilias_root)) {
357 $a_tplname = str_replace($ilias_root,
'', $a_tplname);
359 if (strpos($a_tplname,
'public/Customizing/global/plugins')) {
363 $base_path = $ilias_root;
364 $default = $base_path . $a_in_module . $tpl_sub_path . $a_tplname;
367 if ($skin ===
'default') {
372 $base_path .=
'public/Customizing/skin/' . $skin .
'/' . $style;
374 if ($a_in_module ===
'components/ILIAS/UI/src') {
378 $from_skin = $base_path .
'/' . $a_in_module .
'/' . $a_tplname;
391 if (strpos($a_tplname,
"/") ===
false) {
392 if (
null !== $a_in_module) {
393 $module_path = $a_in_module .
"/";
398 return $module_path . basename($a_tplname);
406 return isset($this->blockvariables[
"content"][$a_variablename]);
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setTemplate(string $template, bool $removeUnknownVariables=true, bool $removeEmptyBlocks=true)
Sets the template.
bool $removeEmptyBlocks
Controls the handling of empty blocks, default is remove.
string $template
Content of the template.
array $blockparents
Array of block parents.
array $blockvariables
Array of variables in a block.
loadTemplatefile(string $filename, bool $removeUnknownVariables=true, bool $removeEmptyBlocks=true)
getUnmodified(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
bool $flagBlocktrouble
Internal flag indicating that a blockname was used multiple times.
Integrated Template Extension - ITX With this class you get the full power of the phplib template cla...
string $activeBlock
Aktueller Block Der wird gemerkt bei der berladenen Funktion setCurrentBlock, damit beim ParseBlock v...
bool $removeUnknownVariables
Controls the handling of unknown variables, default is remove.
findBlocks(string $string)
Recusively builds a list of all blocks within the template.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
free()
Clears all datafields of the object.
setOption(string $option, $value)
Sets the option for the template class.
touchBlock(string $block)
setVariable($variable, $value='')
Sets a variable value.
getTemplatePath(string $a_tplname, string $a_in_module='')
static getCurrentSkin()
get the current skin use always this function instead of getting the account's skin the current skin ...
getFile(string $filename)
Reads a file from disk and returns its content.
blockExists(string $a_blockname)
variableExists(string $a_variablename)
getTemplateIdentifier(string $a_tplname, ?string $a_in_module=null)
get a unique template identifier The identifier is common for default or customized skins but distinc...
parseCurrentBlock()
Parses the current block.
buildBlockvariablelist()
Build a list of all variables within of a block.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
fileExistsInSkin(string $path)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
__construct(Container $dic, ilPlugin $plugin)
fillVars()
all template vars defined in $vars will be replaced automatically without setting and parsing them wi...
static getCurrentStyle()
get the current style or sub style use always this function instead of getting the account's style th...
addBlockFile(string $var, string $block, string $tplname, ?string $in_module=null)
array $blockinner
Array of inner blocks of a block.
array $err
Contains the error objects.
array $blockdata
Array with the parsed content of a block.
__construct(string $file, bool $flag1, bool $flag2, string $in_module="", string $vars=ilGlobalTemplateInterface::DEFAULT_BLOCK, bool $plugin=false, bool $a_use_cache=true)
constructor ilTemplate constructor.
array $vars
variablen die immer in jedem block ersetzt werden sollen
array $blocklist
Array of all blocks and their content.
addBlock(string $placeholder, string $blockname, string $template)
Adds a block to the template changing a variable placeholder to a block placeholder.
buildFunctionlist()
Builds a functionlist from the template.