Skip Menu |

This queue is for tickets about the HTML-Template-Compiled CPAN distribution.

Maintainer(s)' notes

Note: there is a bug with caching and TMPL_INCLUDE_VAR since 0.97_004 until 0.98. either use an earlier version or upgrade to 0.98_001. Another workaround is to precompile all templates to file_cache_dir. The bug happens when including a template via INCLUDE_VAR and the template is not yet compiled or has changed.

I'm sorry if the change about aliases came quite unannounced. I didn't expect any problems since dollar signs are not allowed in template vars, but I heard from at least one case where people were doing exactly this.
Please do not use unallowed characters in template vars. Allowed are (from the HTML::Template::FAQ): Numbers, letters, '.', '/', '+', '-' and '_'.
This should work in HTML::Template::Compiled::Classic.
in HTML::Template::Compiled you should be only using numbers, letters and _.
The dot, for example, is special. If you need to get a hash key from the template parameters with special charcaters, you can try <tmpl_var _.$var$name$with$dollars >

There will be a workaround in the next version:
local $HTML::Template::Compiled::Compiler::DISABLE_NEW_ALIAS = 1;


Please report any bug you find.
The code is now hosted on https://github.com/perlpunk/HTML-Template-Compiled
If you have a bug report, you can also post it there in the "Issues" section.
In the bugreport, please include, if possible, the module version, perl version and a testcase that reproduces the error; that makes it easier to find the bug.

The issue with not reloading includes of includes should be fixed in version 0.95_003. If you have any problems though please report!

Using query() and the dot syntax might not work together always. If you have a tmpL_var name="..foo" (going up the stash one level) the var foo is not detected and will not be reported by the query() function. Since the dot syntax is for dereferencing hashes and method calls the query function might not make sense anyway. I believe it is a bad idea to let the program do things if the template is using a certain variable.

Thanks!

Report information
The Basics
Id: 70689
Status: resolved
Priority: 0/
Queue: HTML-Template-Compiled

People
Owner: Nobody in particular
Requestors: ken.russell [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.95
Fixed in: 0.95_003



Subject: Enhancement Request - JSON escaping mechanism
We would like to use tmpl_vars in some of our JSON objects that are in our HTML Templates. Unfortunately, at the moment we have to escape the variables before registering them with the template as the js escape option will escape an apostrophe but most JSON parsers will complain about escaped apostrophes. http://json.org/ e.g. we would like to do: var test = { "a" : "<tmpl_var escape='ijson' name='myvar'>" }; I'm using "ijson" opposed to json given our variable is inside quotes and we would rather not have external quotes. I've attached a patch which basically adds a new escape method called ijson (js escape without escaping the apostrophe). Not sure how you feel about this. It's a bit of a hack. I'm happy to maintain something like this at my side if it gets rejected. Thanks!
Subject: patch.txt
--- Compiler.pm.orig Wed Apr 27 12:10:27 2011 +++ Compiler.pm Thu Sep 1 15:45:31 2011 @@ -117,6 +117,11 @@ _expr_function( 'HTML::Template::Compiled::Utils::escape_js', $exp, ); } + elsif ( $_ eq 'IJSON' ) { + $exp = + _expr_function( 'HTML::Template::Compiled::Utils::escape_ijson', + $exp, ); + } elsif ( $_ eq 'DUMP' ) { $exp = _expr_method( 'dump', _expr_literal('$t'), $exp, ); } --- Utils.pm.orig Wed Apr 27 12:10:27 2011 +++ Utils.pm Thu Sep 1 15:41:24 2011 @@ -11,14 +11,14 @@ @EXPORT_OK = ( @paths, qw( &log &stack - &escape_html &escape_html_all &escape_uri &escape_js + &escape_html &escape_html_all &escape_uri &escape_js &escape_ijson &md5 ) ); %EXPORT_TAGS = ( walkpath => \@paths, log => [qw(&log &stack)], - escape => [qw(&escape_html &escape_uri &escape_js)], + escape => [qw(&escape_html &escape_uri &escape_js &escape_ijson)], ); # These should be better documented @@ -195,7 +195,24 @@ sub escape_js { my ($var) = @_; return $var unless defined $var; - $var =~ s/(["'])/\\$1/g; + $var =~ s/([\\"'])/\\$1/g; + $var =~ s/\r/\\r/g; + $var =~ s/\n/\\n/g; + return $var; +} + +=head2 escape_ijson + + my $escaped_ijson = escape_ijson($raw_json); + +JavaScript-escapes the input string except for the apostrophe and returns it, so it can be used within a JSON element; + +=cut + +sub escape_ijson { + my ($var) = @_; + return $var unless defined $var; + $var =~ s/([\\"])/\\$1/g; $var =~ s/\r/\\r/g; $var =~ s/\n/\\n/g; return $var;
Am Do 01. Sep 2011, 18:59:29, kenrussell schrieb: Show quoted text
> We would like to use tmpl_vars in some of our JSON objects that are in > our HTML Templates. Unfortunately, at the moment we have to escape the > variables before registering them with the template as the js escape > option will escape an apostrophe but most JSON parsers will complain > about escaped apostrophes. http://json.org/
thanks, I wasn't aware of that. sounds very useful and should be in core, I think. will be working on it as soon as possible (as usual this can take some time, I'm doing a lot of work at the moment...) regards, tina
I implemented this in 0.95_003. Since I also did a change to the caching mechanism I'll wait some time if anyone reports problems, and then I think I'll do a major release. (I have not forgotten your other issues with the tmpl var names, just didn't have time so far =)