PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_Template_IT » Bug #192

No replacements = no output

Details

Submitted2003-11-04 14:39 UTC
Fromadam at tux dot appstate dot edu
StatusBogus
PackageHTML_Template_IT
PHP Version4.3.2
OSRehHat Linux 9
Roadmaps(Not assigned)

Comments

[2003-11-04 14:39 UTC] adam at tux dot appstate dot edu

Description:
------------
If you create a template file that does not have any replacements but contains valid html that you wish to have displayed, nothing is displayed when using the get() function. But if you force a single replacement within the file, the output will be shown. This poses a problem when parsing files that may or may not have replacements. As a simple example, you can use a "shell" template and a "nut" template. Obviously the nut goes in the shell. But the nut may or may not contain replacements.

Reproduce code:
---------------
Shell.html:
<html>
<head><title>{TITLE}</title></head>
<body>
{CONTENT}
</body>
</html>

Nut1.html:
<table border="1">
{ITEMS}
</table>

Nut2.html:
<b>No items were found!</b>

Expected result:
----------------
If we find items to show the user then nut1 is used in the shell, otherwise nut2 is used. When no items are present the expected output is an html page with "No items were found!" placed where the {CONTENT} variable is in the shell. However, we instead get a blank page with head information.

Actual result:
--------------
The actual result is, if we have items to show the user, they will be shown fine since the template replacement is being done, but if no items were found the actual output is just an empty html page with the head information from shell.html.

[2003-11-04 20:58 UTC] adam at tux dot appstate dot edu

OK That worked but it's actually a little different than you told me. The function is loadTemplateFile not setTemplateFile and you need to pass FALSE as the last 2 arguements, not TRUE:

$tpl->loadTemplateFile($template, FALSE, FALSE);

This tells the parser to NOT remove unknown blocks or variables. Personally, I think these should default to FALSE since there is very few times when you want it to remove things you don't know about.

Thanks for your help Pierre!

[2005-07-26 08:46 UTC] zmbpetr at seznam dot cz

Hello,

I think it's still not working.

I have a valid html template:
<html>
<head>
<title>{title}</title>
</head>
<body>
</body>
</html>

and script:
$this->template->setTemplate($tpl, true, true);

output is: nothing (bug?)

but if i define variable "title" (setVariable) it come to work.
---

another options to print result:
setTemplate($tpl, false, false);
output is: {title} (correct html in result with {title] tag in head, but I will not print this tag - no setVariable method called)

setTemplate($tpl, true, false);
output is: nothing (no html in result)

setTemplate($tpl, false, true);
output is: {title} (correct html in result with {title] tag in head, but I will not print this tag - no setVariable method called)
---

I want to display html tags (from template) without unknown tags ({title}). Is there any way to do this? Without calling setVariable? (because now I have to declare empty tag on every template and than calling setVarible method)

Thanks for answer.
Regards,
Petr Pospisil

[2005-07-26 09:17 UTC] pierre at dotgeek dot org

See previous comment.