in reply to Doubt about Template Toolkit

I just noticed that your template is a complete HTML page (with two <head> tags, btw). So, you are printing two complete HTML pages to STDOUT. Your browser will read until the first </html> and then do the refresh. What behavior do you expect from that application?

Replies are listed 'Best First'.
Re^2: Doubt about Template Toolkit
by logangha (Acolyte) on Jul 18, 2022 at 15:04 UTC

    At last...!!!! My solution:

    [%# formReference.ttml %] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <TITLE>Please select your option</TITLE> <STYLE type="text/css"> select{display:inline-block;} div{text-align:center; border:1px solid gray;} </STYLE> </head> </head> <body> <form> <input type="hidden" id="preUrl" value="[% pre %]"> <input type="hidden" id="postUrl" value="[% post %]"> <div> <select name="url" id="url" onchange="update();"> [% FOREACH url IN urls -%] <option value="[% url.value %]">[% url.key %]</option> [% END -%] </select> <p id="p"></p> </div> <script type="text/javascript" charset="UTF-8"> function update() { var select = document.getElementById('url'); var option = select.options[select.selectedIndex]; var preUrl = document.getElementById('preUrl').value; var postUrl = document.getElementById('postUrl').value; var newUrl = preUrl + encodeURI(option.value) + "&transient +name=" + option.text + postUrl; document.getElementById("p").textContent = "Reference selec +ted: " + option.text; try { var newWindow ="", '_blank', 'toolbar=0,loc +ation=0,menubar=0'); newWindow.location.href = newUrl; } catch(ex) { document.getElementById('value').value = ex; } } update(); </script> </form> </body> </html>

    Thanks all for your valuable help. I appreciate it.

      The days were browsers freely allowed sites to open as many windows/tabs as they wanted are thankfully long gone.

      But this might help in a private app, if you allow it explicitly in the browser settings, YMMV.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Re^2: Doubt about Template Toolkit
by Anonymous Monk on Jul 15, 2022 at 15:04 UTC

    Hi haj, that ttml file was incorrect. This is the correct one

    [%# template.ttml %] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <TITLE>Some title</TITLE> <meta http-equiv="refresh" content="$link" /> </head> <body> <center> </center> <form action=""> </form> </body> </html>

    The idea with all of this, is when this cgi is executed, every processed url appears in a new tab. But first url does that, second url does not do anything. I made changes to cgi script to see that it reached after loop is executed and it efectively did. That is why I mention that second url is not executed.

      It is not TT's fault that this doesn't work as expected: Browsers don't work that way. If you use refresh (I'd recommend that you check the syntax, you did not specify the intended delay), browsers are not supposed to open a new tab.

      Also, hash keys are returned in random order, so you can't say for sure which of the URLs is inserted into the template first.

      If you are on Linux and have LWP installed, the easiest way to check your CGI is the following command:


        I am developing in an AIX server, so I do not know if LWP is installed. Is there any way to check if URL sql text is correct with all these characters used?: ',() (quotes, commas or parenthesis). Because that is why I am using meta http-equiv, with this does not matter if sql text has single quotes, commas or parenthesis. Now I am trying to use JS and another problem arises with these characters.

      The idea with all of this, is when this cgi is executed, every processed url appears in a new tab

      Sending multiple HTML documents to the browser will not achieve this...

      I think I would approach this by adding all the URLs into an array and passing a reference to the array into Template to process a single template file. In the template file, have a some Javascript and a FOREACH loop that adds the Javascript calls to for each URL.

      Rather than processing the template file multiple times within Perl, assemble the data in Perl and pass that once to the template file and let that do the iterations.