template-engine

Render an ERB template with values from a hash

让人想犯罪 __ 提交于 2019-11-28 15:56:35
问题 I must be overlooking something very simple here but I can't seem to figure out how to render a simple ERB template with values from a hash-map. I am relatively new to ruby, coming from python. I have an ERB template (not HTML), which I need rendered with context that's to be taken from a hash-map, which I receive from an external source. However, the documentation of ERB, states that the ERB.result method takes a binding . I learnt that they are something that hold the variable contexts in

What is the best way to insert HTML via PHP?

亡梦爱人 提交于 2019-11-28 15:55:01
Talking from a 'best practice' point of view, what do you think is the best way to insert HTML using PHP. For the moment I use one of the following methods (mostly the latter), but I'm curious to know which you think is best. <?php if($a){ ?> [SOME MARKUP] <?php } else{ ?> [SOME OTHER MARKUP] <?php } ?> Opposed to: <?php unset($out); if($a) $out = '[SOME MARKUP]'; else $out = '[OTHER MARKUP]'; print $out; ?> Kent Fredric If you are going to do things that way, you want to separate your logic and design, true. But you don't need to use Smarty to do this. Priority is about mindset. I have seen

Create new file from templates with bash script

给你一囗甜甜゛ 提交于 2019-11-28 15:49:00
问题 I have to create conf files and init.d which are very similar. These files permit to deploy new http service on my servers. These files are the same and only some parameters change from one file to another ( listen_port , domain, path on server...). As any error in these files leads to misfunction of service I would like to create these files using a bash script. For example: generate_new_http_service.sh 8282 subdomain.domain.com /home/myapp/rootOfHTTPService I am looking for a kind of

Create new file from templates with bash script

半城伤御伤魂 提交于 2019-11-28 15:47:52
I have to create conf files and init.d which are very similar. These files permit to deploy new http service on my servers. These files are the same and only some parameters change from one file to another ( listen_port , domain, path on server...). As any error in these files leads to misfunction of service I would like to create these files using a bash script. For example: generate_new_http_service.sh 8282 subdomain.domain.com /home/myapp/rootOfHTTPService I am looking for a kind of templating module that I could use with bash. This templating module would use some generic conf and init.d

How do I pass node.js server variables into my angular/html view?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 08:31:15
I have this route in my app.js file that starts the server app.get('/view/:item_id', function(req,res){ var A = 5; res.render('view_item'); and I have this in my view_item.html: <p>{{A}}</p> I want it to display the variable value - 5. If I were using a template engine such as jade it would be easy. I could change that third line of my server code to res.render({A:A},'view_item'); But I am using html as my template engine. My research so far has told me that using a template engine with angular is usually a bad idea, and there is always a way to do it using angular's built in template system.

Dynamic Dropdown in Node.js

流过昼夜 提交于 2019-11-28 06:35:33
问题 Newbie to Node.js here: What is an easy way to make dynamic dropdowns in node.js? Basically, I have two tables: Skill and Skill_Category . I want to select from the Skill_Category and be presented with the associated Skill . I would assume I would need to use some template engine (to render in a webpage). I tried researching a good amount on google, but didn't turn up anything that helped me. If anyone can point me in the right direction? Thank you! 回答1: So one dropdown will cause the other

Play! framework: define a variable in template? [duplicate]

独自空忆成欢 提交于 2019-11-28 06:25:59
This question already has an answer here: Declare variable in a Play2 scala template 8 answers I'm passing to a template an Event object and what I need to do is checking @event.getSeverity value. if the value is positive, I want to color a specific <div> in green. if the value is negative I want to color a specific <div> in red. I couldn't find a way to define a variable. is it possible? it should be I think. anyhow, what's the simplest way accomplishing this? thanks As stated in the Play documentation you can use the @defining helper. @defining(if (event.getSeverity > 0) "green" else "red")

How do I execute ruby template files (ERB) without a web server from command line?

[亡魂溺海] 提交于 2019-11-28 04:53:35
I need ERB (Ruby's templating system) for templating of non-HTML files. (Instead, I want to use it for source files such as .java, .cs, ...) How do I "execute" Ruby templates from command line? You should have everything you need in your ruby/bin directory. On my (WinXP, Ruby 1.8.6) system, I have ruby/bin/erb.bat erb.bat [switches] [inputfile] -x print ruby script -n print ruby script with line number -v enable verbose mode -d set $DEBUG to true -r [library] load a library -K [kcode] specify KANJI code-set -S [safe_level] set $SAFE (0..4) -T [trim_mode] specify trim_mode (0..2, -) -P ignore

How to retrieve all Variables from a Twig Template?

*爱你&永不变心* 提交于 2019-11-28 04:53:22
Is it possible to retrieve all variables inside a Twig template with PHP? Example someTemplate.twig.php: Hello {{ name }}, your new email is {{ email }} Now I want to do something like this: $template = $twig->loadTemplate('someTemplate'); $variables = $template->getVariables(); $variables should now contain "name" and "email". The reason I want to do this is that I am working on a CMS system where my twig templates and variables are dynamically set by my users and they also fill the variables through an API. I want to set default values to not-set variables and therefore I need a list of all

Declare CSS style outside the “HEAD” element of an “HTML” page?

[亡魂溺海] 提交于 2019-11-28 03:53:36
my use-case is the following : I'm composing an HTML page by using parts that are valid HTML fragments but not valid pages, like Divs ; these elements are using CSS to manage their style. I'd like to allow each fragment to be responsible for its own styling requirements and to not rely on the declarations of style-sheets in the main fragment (the one with the "HTML" tag). So here come the question : is there any (standard) way to add some CSS styling outside the HEAD element (excluding the inline styling via the "style" attribute) ? I guess I could use frames but I'd prefer to avoid this