19declare(strict_types=1);
21require_once __DIR__ .
'/../lib/html-it/IT.php';
22require_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);
193 $this->activeBlock = $part;
194 return parent::setCurrentBlock($part);
207 return parent::touchBlock($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 ||
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;
366 $skin = $this->getCurrentSkin();
367 if ($skin ===
'default') {
371 $style = $this->getCurrentStyle();
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;
380 return $this->fileExistsInSkin($from_skin) ? $from_skin : $default;
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]);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Integrated Template Extension - ITX With this class you get the full power of the phplib template cla...
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.
free()
Clears all datafields of the object.
buildBlockvariablelist()
Build a list of all variables within of a block.
array $blockparents
Array of block parents.
bool $removeEmptyBlocks
Controls the handling of empty blocks, default is remove.
setOption(string $option, $value)
Sets the option for the template class.
array $blockinner
Array of inner blocks of a block.
string $template
Content of the template.
findBlocks(string $string)
Recusively builds a list of all blocks within the template.
array $blockdata
Array with the parsed content of a block.
getFile(string $filename)
Reads a file from disk and returns its content.
parseCurrentBlock()
Parses the current block.
setTemplate(string $template, bool $removeUnknownVariables=true, bool $removeEmptyBlocks=true)
Sets the template.
array $blocklist
Array of all blocks and their content.
array $err
Contains the error objects.
array $blockvariables
Array of variables in a block.
setVariable($variable, $value='')
Sets a variable value.
bool $flagBlocktrouble
Internal flag indicating that a blockname was used multiple times.
bool $removeUnknownVariables
Controls the handling of unknown variables, default is remove.
static getCurrentSkin()
get the current skin use always this function instead of getting the account's skin the current skin ...
static getCurrentStyle()
get the current style or sub style use always this function instead of getting the account's style th...
special template class to simplify handling of ITX/PEAR
variableExists(string $a_variablename)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
init()
Clears all datafields of the object and rebuild the internal blocklist LoadTemplatefile() and setTemp...
getTemplatePath(string $a_tplname, string $a_in_module='')
addBlockFile(string $var, string $block, string $tplname, ?string $in_module=null)
__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.
string $activeBlock
Aktueller Block Der wird gemerkt bei der berladenen Funktion setCurrentBlock, damit beim ParseBlock v...
blockExists(string $a_blockname)
Checks wheter a block exists.
fillVars()
all template vars defined in $vars will be replaced automatically without setting and parsing them wi...
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
loadTemplatefile(string $filename, bool $removeUnknownVariables=true, bool $removeEmptyBlocks=true)
Reads a template file from the disk.
array $vars
variablen die immer in jedem block ersetzt werden sollen
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...
getUnmodified(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
touchBlock(string $block)
fileExistsInSkin(string $path)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc