templating

Shopify liquid get related blog posts

99封情书 提交于 2019-12-06 13:37:27
In shopify I am using liquid templating to get blog posts which are related to products by their tags, like so: <ul> {% for article in blogs.blog.articles %} {% if article.tags contains product.handle %} <li><a href="{{ article.url }}"><p>{{ article.title }}</p></a></li> {% endif %} {% endfor %} </ul> However, if there are no related posts, I would like to display a message such as "No related posts!" My question is how would I do that? I have contemplated trying to get the articles into an array and testing if it is empty, but I am having difficulty finding out how this is done. Thanks! Try

Loading underscore.js templates from a separate file

六月ゝ 毕业季﹏ 提交于 2019-12-06 12:59:05
I'm currently using underscore.js for templating in a project, templates are stored in script tags with a type of text/template and loaded by id. I'm wondering if it's possible to continue to use the same system, but move the templates to a separate file? The only way I can think about doing this is declaring the templates as global vars in a separate file, but that seems ugly. Note: I don't want to use Jammit or some other build system for mashing everything together into a single file at deployment time, wondering if there's another solution. I personally use RequireJS to load my templates

How to evaluate javascript functions in underscore with mustache notation?

不问归期 提交于 2019-12-06 12:24:30
I want to do something like this: <script id="tmpl-books" type="text/template"> <ul> <% for (var i = 0; i < books.length; i++) { %> <% var book = books[i]; %> <li> <em><%= book.title %></em> by <%= book.author %> </li> <% } %> </ul> </script> in my code, but I am using JSP so I have to use the {{ }} notation, but when I do this {{ for(var... }} does not work. <script id="tmpl-books" type="text/template"> <ul> {{ for (var i = 0; i < books.length; i++) { }} <% var book = books[i]; %> <li> <em>{{= book.title }}</em> by {{ book.author }} </li> {{ } }} </ul> </script> How can I achieve this? mu is

Pagination with Twig

妖精的绣舞 提交于 2019-12-06 03:47:24
问题 I've been trying Twig, and it works well for my small site. This was the tutorial used: http://devzone.zend.com/article/13633 However, I've had a look online and cannot find anything to do pagination. This is my code: <html> <head> <style type="text/css"> table { border-collapse: collapse; } tr.heading { font-weight: bolder; } td { border: 0.5px solid black; padding: 0 0.5em; } </style> </head> <body> <h2>Automobiles</h2> <table> <tr class="heading"> <td>Vehicle</td> <td>Model</td> <td>Price<

Iterate through keys/values in Hogan.js

a 夏天 提交于 2019-12-06 00:27:28
Is there a way to iterate through keys and values in an object using Hogan.js? I'm unable to find such documented functionality - only iteration over arrays seems to be documented. Is it even possible to iterate through objects in hogan.js (or any other moustache.js implementation)? There is no way to directly iterate over the keys and values in an object in Hogan.js, what sub_stantial is doing is essentialy iterating over an array. Depending on what you want to do you need a bit of prerender code. Supposing you have an object o that is { k1: "v1", k2: "v2" } . And you want your rendered

How to programmatically evaluate EL in a managed bean

一世执手 提交于 2019-12-06 00:03:34
I would like to add a simple template language to my application based on Seam / JSF to let the users compose their own email. Since I don't want to create a new parser, I would like to use the Unified Expression Language setting the context all by myself. How can I do that? If you're sitting inside the JSF context, then just use Application#evaluateExpressionGet() to programmatically evaluate a string containing EL expressions. String unevaluatedString = convertMailTemplateToStringSomehow(); FacesContext context = FacesContext.getCurrentInstance(); String evaluatedString = context

Smarty - 'unable to write file… templates_c'. (smarty_internal_write_file.php:44) [closed]

给你一囗甜甜゛ 提交于 2019-12-05 17:40:56
I'm using Smarty for the first time. It works fine on my laptop (MAMP) but when I try and run a basic template on my production server (Windows) I get this error message: Fatal error: Uncaught exception 'SmartyException' with message 'unable to write file C:\Inetpub\vhosts\path\to\web\root\smarty\templates_c\wrt516e53290e2095.47946913' in C:\Inetpub\vhosts\path\to\web\root\smarty\libs\sysplugins\smarty_internal_write_file.php:44 Stack trace: #0 C:\Inetpub\vhosts\path\to\web\root\smarty\libs\sysplugins\smarty_internal_template.php(201): Smarty_Internal_Write_File::writeFile('C:\Inetpub\vhos...'

How do I render partials with jade without express.js?

…衆ロ難τιáo~ 提交于 2019-12-05 17:13:44
问题 Only info I found was this: http://forrst.com/posts/Node_js_Jade_Import_Jade_File-CZW I replicated the suggested folder structure (views/partials) But it didn't work, as soon as I put !=partial('header', {}) !=partial('menu', {}) into index.jade, I get a blank screen, the error message I receive from jade is: ReferenceError: ./views/index.jade:3 1. 'p index' 2. '' 3. '!=partial(\'header', {})' partial is not defined I'd be very grateful for any help ! (I strongly prefer not to use express.js)

Creating active navigation state with Meteor and Iron Router

*爱你&永不变心* 提交于 2019-12-05 16:58:10
I want to add a class of 'active' to the nav list item that is currently being rendered by Iron Router. Here's my markup: <ul> <li> {{#linkTo route="option1"}} <span class="fa fa-fw fa-option"></span> Option 1 {{/linkTo}} </li><li> {{#linkTo route="option2"}} <span class="fa fa-fw fa-option"></span> Option 2 {{/linkTo}} </li> </ul> I've read through the guide and various articles but can't find this covered anywhere. Assuming I'll need some sort of helper? I think you might find meteor-iron-router-active useful, as it has helpers for the following: isActiveRoute isActivePath Here's how I do it

How do I use a template code generator (eg freemarker) in Maven?

人盡茶涼 提交于 2019-12-05 15:56:44
问题 How would you structure Freemarker (or an alternative) as a templating code generator into a Maven project? I'm pretty new to Maven and would appreciate some help. I want to generate some code from templates in my project. [a] Rather than write my own, googling found freemarker which appears to be used by Spring which is a good enough reference for me, though as I haven't started with it yet, any other suggestions that work well with Maven would be appreciated too. This website tells me how