templating

Rendering templates within helpers in handlebars

≡放荡痞女 提交于 2019-12-03 12:31:07
Hey guys! Because there seem to be no answer on this: Passing variables through handlebars partial yet, I'm currently working on a little workaround to get this work. So, the idea is to register a helper function which renders a specific template with possible values. A bit code makes it better to understand. This is how a I'd invoke my helper: <div> {{myHelper}} </div> This helper is registered with this little code: hbs.registerHelper(name, function (args) { args = args || {}; var template = hbs.compile(fs.readFileSync(__dirname + '/' + file, 'utf8')); return template(args); }); I put this

HTML Templates — php?

安稳与你 提交于 2019-12-03 12:19:39
So, I'm making a site about WWI as a school assignment, and I want this to appear in every document: <!DOCTYPE html> <html> <head> <title>1914</title> <script src="modernizr-1.5.js"></script> <link href="styles.css" type="text/css" rel="stylesheet" /> <meta charset="utf-8" /> </head> <body> <div id="container"> <header> <img src="images/banner.png" alt="World War I" style="border: none"/> <nav> <ul> <a href="index.htm"><li><span>Home</span></li></a> <a href="1914.htm"><li><span>1914</span></li></a> <a href="1915.htm"><li><span>1915</span></li></a> <a href="1916.htm"><li><span>1916</span></li><

Best way to handle data attributes in Slim

吃可爱长大的小学妹 提交于 2019-12-03 10:26:47
问题 I was evaluating Slim as a replacement for HAML in a personal project, and it doesn't appear to handle HTML5 data attributes as gracefully as HAML. I was hoping someone may have also run into this, or may have known about an option/syntax I haven't yet found in their docs. HAML allows you to define HTML 5 data attributes simply by using nested hashes like so: %a{data: {key1: 'val', key2: 'val'}} resulting in <a data-key1='val' data-key2='val'></a> 回答1: There are multiple ways in Slim As Hash

Mustache.php : Idiomatic ways to template select dropdowns

五迷三道 提交于 2019-12-03 09:41:36
问题 So I'm having some problems wrapping my head around the best idiomatic way to deal with some complex html cases flexibly using Mustache.php The first is a pre-selected select dropdown, e.g. <select> <option value=''></option> <option value='bob'>Bob Williams</option> <option value='james' selected>James Smith</option> </select> I have a way that I deal with this, but my way seems really inflexible: take an array in php, reformat it into multi-dimensional arrays with 3 elements; value, display

Include HTML blocks Using node.js

匆匆过客 提交于 2019-12-03 09:19:46
问题 This is what I want but probably can't have: Using node.js and express and maybe ejs, I would like to, while writing a regular HTML file in my client dir, server-side-include a template block of HTML. It would be cool also if I could pass variables into the include from the HTML document. Sooo something like: <!doctype html> <html> <head> <%include head, ({title: "Main Page"}) %> </head> <body> <% include header, ({pageName: "Home", color: "red"}) %> ... <<% include footer%>> </body> </html>

render_to_string in lib class not working

两盒软妹~` 提交于 2019-12-03 04:57:10
I'm trying to use delayed_job to update a remote database via xml In my lib folder I put a file with a class that should do a render_to_text with template.xml.builder , but I get: undefined method `render_to_string' for #<SyncJob:0x7faf4e6c0480>... What am I doing wrong? ac = ActionController::Base.new() ac.render_to_string(:partial => '/path/to/your/template', :locals => {:varable => somevarable}) Germano I had problems with a undefined helper method then I used ApplicationController ApplicationController.new.render_to_string render_to_string is defined in ActionController::Base . Since the

Internationalization with angularjs

社会主义新天地 提交于 2019-12-03 03:47:19
问题 I'm thinking of moving my site to angularjs, and I want to start very small, by moving all my static server-side plain-text templating from django to angular (otherwise there will be syntax trouble with the '{{}}'). It seems that the best way to do that will be one of two options: To have an ajax call that returns a JSON with all the texts of my site. The texts will be stored in a variable which is binded to my HTML elements so angular will update everything. To store a static js file with

Why don't I just build the whole web app in Javascript and Javascript HTML Templates?

﹥>﹥吖頭↗ 提交于 2019-12-03 02:02:31
问题 I'm getting to the point on an app where I need to start caching things, and it got me thinking... In some parts of the app, I render table rows (jqGrid, slickgrid, etc.) or fancy div rows (like in the New Twitter) by grabbing pure JSON and running it through something like Mustache, jquery.tmpl, etc. In other parts of the app, I just render the info in pure HTML (server-side HAML templates), and if there's searching/paginating, I just go to a new URL and load a new HTML page. Now the problem

Best way to handle data attributes in Slim

谁都会走 提交于 2019-12-03 00:54:17
I was evaluating Slim as a replacement for HAML in a personal project, and it doesn't appear to handle HTML5 data attributes as gracefully as HAML. I was hoping someone may have also run into this, or may have known about an option/syntax I haven't yet found in their docs. HAML allows you to define HTML 5 data attributes simply by using nested hashes like so: %a{data: {key1: 'val', key2: 'val'}} resulting in <a data-key1='val' data-key2='val'></a> There are multiple ways in Slim As Hash Attributes which will be hyphenated if a Hash is given (e.g. data={a:1,b:2} will render as data-a="1" data-b

Include HTML blocks Using node.js

蓝咒 提交于 2019-12-02 23:31:40
This is what I want but probably can't have: Using node.js and express and maybe ejs, I would like to, while writing a regular HTML file in my client dir, server-side-include a template block of HTML. It would be cool also if I could pass variables into the include from the HTML document. Sooo something like: <!doctype html> <html> <head> <%include head, ({title: "Main Page"}) %> </head> <body> <% include header, ({pageName: "Home", color: "red"}) %> ... <<% include footer%>> </body> </html> Is there anyhting in node world that works like this? Or any thing that comes close and that could be