template-engine

PHP as template engine stored in Mysql - Whitelist Functions

巧了我就是萌 提交于 2019-12-13 07:49:24
问题 While I have been reading through countless posts about using PHP as a template engine (using output buffering), I'm still trying to make a case for it. As I'm wondering if I could use PHP as a template engine for a web app (users will be able to change the layout themselves) -- I still don't find any info regarding the following: Store the templates in a MYSQL database Eval them BUT only include functions that are whitelisted (to give them only access to a limited set of functions -- while,

Php regex, match if { } characters isn't presented

烈酒焚心 提交于 2019-12-13 01:28:19
问题 I'm currently working on my own template engine for educational purposes. Now I'm stuck at this part where I want to match if the string contains the following for e.g: $article.author Here's my regex pattern so far: http://www.phpliveregex.com/p/fx2 Current pattern matches both {$article.author} and $article.author . But it should only match $article.author . Any help would be greatly appreciated, Jumpy. 回答1: You need to use anchors for finding exact match as ^\$[^|{}]*$ Regex Demo PHP Code

JSON.parse() in Swig (Node.js)?

空扰寡人 提交于 2019-12-12 20:20:35
问题 I'm trying to switch from Jade to Swig (lured by Swig's insane performance) as my Express template engine when I got stuck here — I'm sending an array of serialized JSON from Express into Swig and retrieve the data in Swig using this loop here: <ul id = "list"> {% if items %} {% for item in items %} {{ JSON.parse( item ).title }} {% endfor %} {% endif %} </ul> ... but I get this: SyntaxError: Unexpected token ) at Object.Function (unknown source) at createTemplate (/home/vijay/node_modules

Could not read properties if it contains dollar symbol (${var})

折月煮酒 提交于 2019-12-12 20:07:11
问题 I have property file with following content: INVALID_ARGUMENT=Field ${fieldName} is invalid or missing. I read this using spring configuration: @PropertySource("error_messages_en.properties") @Configuration public static class ErrorMessagesEn { @Value("${INVALID_ARGUMENT}") private String invalidArgument; } But after application start I see: Could not resolve placeholder 'fieldName' in value "Ïîëå ${fieldName} íåêîððåêòíî çàïîëíåíî èëè ïðîïóùåíî." I need ${fieldName} because I want to use

Jinja, get line of source code after template rendering

社会主义新天地 提交于 2019-12-12 12:32:37
问题 Is it possible to get line of source code for each line of rendered template? For example if we have template like below: some_expr {% if true %} other_expr {% endif %} So, after template rendering following text is produced: some_expr other_expr I want to get information that 'some_expr' is produced from 1st line of template source code, and 'other_expr' if produced from 3rd line. Even better if I can get file name and line from which rendered line is produced (in case of including other

StringTemplate invalid character '<' when reading XML Template

醉酒当歌 提交于 2019-12-12 10:36:31
问题 I am trying to create a simple XML-Template which so far only consists of: <?xml version="1.0"?> I read the file like this: STGroup group = new STGroupDir("templates"); ST st = group.getInstanceOf("report"); st.add("analysis", ana); String result = st.render(); System.out.println(result); And the result is several error messages: report.st 1:1: invalid character '<' report.st 1:1: invalid character '?' report.st 1:19: invalid character '?' report.st 1:20: invalid character '>' report.st 1:2:

Can I run a ASPX and grep the result without making HTTP request?

喜你入骨 提交于 2019-12-12 07:16:59
问题 How can I just make a function call, without URL, and without HTTP, to a simple ASP.NET file, and capture the byte stream it generated? More background information, I need a some kind of template can put a little logic inside, to render some INI like text files. I give up those libraries ported from Java and come up a solution of using ASP.NET for template engine. (I am NOT using it to build a website, not even a HTML.) I have written a ASP.NET page (no WebForm, no MVC), which accept a XML

how to use Smarty better with PHP?

馋奶兔 提交于 2019-12-12 07:15:26
问题 I found that using Smarty with PHP, sometimes extra time will need to be used for 1) using quite different syntax than PHP itself 2) need to check small cases, because documentation doesn't give finer details, such as for "escape" http://www.smarty.net/manual/en/language.modifier.escape.php it doesn't say escape:"quotes" is for double quotes only or for single quotes as well, so you need to write code to test it. Also for the case of escape:"javascript" -- can't tell exactly what and how it

Globbing in template path not working in nunjucks with gulp

谁说胖子不能爱 提交于 2019-12-12 04:29:49
问题 I'm using this gulp plugin to use nunjucks to make HTML management easier. https://github.com/carlosl/gulp-nunjucks-render gulp.task('default', function () { return gulp.src('src/templates/*.html') .pipe(nunjucksRender({ path: ['src/templates/'] // String or Array })) .pipe(gulp.dest('dist')); }); I want to keep my templates and partials of specific pages under page's directory in different folders so I tried this to keep the path as path: ['src/templates/', 'src/common-partials/', 'src/pages

Is there a better way to apply a nl2br filter with Jinja/Flask?

怎甘沉沦 提交于 2019-12-11 18:33:43
问题 I'm using Jinja with Flask (autoescape enabled) and I'm attempting to apply this filter import re from jinja2 import evalcontextfilter, Markup, escape _paragraph_re = re.compile(r'(?:\r\n|\r|\n){2,}') app = Flask(__name__) @app.template_filter() @evalcontextfilter def nl2br(eval_ctx, value): result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', '<br>\n') \ for p in _paragraph_re.split(escape(value))) if eval_ctx.autoescape: result = Markup(result) return result The problem with it is that it