templating

Internationalization with angularjs

社会主义新天地 提交于 2019-12-02 17:13:37
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 the dictionary and include it in my HTML and bind the dictionary with angularjs. Both options will allow

Mustache - how can I do something *once* for an iterable?

◇◆丶佛笑我妖孽 提交于 2019-12-02 00:10:40
问题 Say I have a user , who has many items How can I have a single 'Sweet, you have items!', provided there's at last one item in items ? {{#user.items}} Sweet, you have items! {{/user.items}} Note : I know I can create a section that will repeat for each item. But right now I don't want to do that. 回答1: The answer (like most things Mustache) is "prepare your view model before rendering" :) But if you're not into that, you can usually fake it in Mustache.js like this: {{# user.items.0 }} Sweet,

Mustache - how can I do something *once* for an iterable?

纵然是瞬间 提交于 2019-12-01 20:42:32
Say I have a user , who has many items How can I have a single 'Sweet, you have items!', provided there's at last one item in items ? {{#user.items}} Sweet, you have items! {{/user.items}} Note : I know I can create a section that will repeat for each item. But right now I don't want to do that. The answer (like most things Mustache) is "prepare your view model before rendering" :) But if you're not into that, you can usually fake it in Mustache.js like this: {{# user.items.0 }} Sweet, you have items! {{/ user.items.0 }} (The more Mustachey way would be to add a hasItems property or function

Modulus/Modulo equivalent operator/function in django templates?

放肆的年华 提交于 2019-11-30 18:49:08
I'm just learning django's templating system and trying to do something relatively trivial: <h2>State</h2> <ul class="states"> {% for state in states %} <li class="state_elements" ><a href="/{{ state.name }}/"> {{ state.name }}</a></li> {% if forloop.counter \% 3 == 0 %} <br style="clear: both"/> {% endif %} {% endfor %} </ul> I get a syntax error because % is a symbol reserved for the templating language. This is unfortunate. I already found a partial solution with {% cycle "" "" "" '<br style="clear: both"/>' %} but it strikes me as damn odd. Is there a better way? divisibleby Returns True

Twig: Include external Code from an SVG file

爱⌒轻易说出口 提交于 2019-11-30 18:15:59
Is it possible to inlcude code from a svg file directly into a twig template file? Something like: {% include 'my.svg' %} that will result in: <svg viewbox=".... /> One way of doing this: {{ source('my.svg') }} Read more here: https://www.theodo.fr/blog/2017/01/integrating-and-interacting-with-svg-image-files-using-twig/ LT86 Had a similar issue, ended up renaming my svgs to be .twig files. {% include 'my.svg.twig' %} You can do in a Drupal8 theme via setting a new variable: function theme_preprocess_page(&$variables) { $svg = file_get_contents(drupal_get_path('theme', 'socialbase') . '/images

how to use Smarty better with PHP?

大兔子大兔子 提交于 2019-11-30 13:58:29
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 is escaped. 3) for something complicated, need to write helper functions or modifiers, so it needs a

Modulus/Modulo equivalent operator/function in django templates?

笑着哭i 提交于 2019-11-30 03:49:16
问题 I'm just learning django's templating system and trying to do something relatively trivial: <h2>State</h2> <ul class="states"> {% for state in states %} <li class="state_elements" ><a href="/{{ state.name }}/"> {{ state.name }}</a></li> {% if forloop.counter \% 3 == 0 %} <br style="clear: both"/> {% endif %} {% endfor %} </ul> I get a syntax error because % is a symbol reserved for the templating language. This is unfortunate. I already found a partial solution with {% cycle "" "" "" '<br

Partial HAML templating in Ruby without Rails

寵の児 提交于 2019-11-29 23:10:47
I really don’t need the overhead of Rails for my very small project, so I’m trying to achieve this just using just plain Ruby and HAML. I want to include another HAML file inside my HAML template. But I haven’t found a good—or really usable—way of doing this. For example, I have these two HAML files: documents.haml %html %body = include(menu.haml) body %article … menu.haml %ul %li %a whatever … Include is obviously not the way to go here. But it does a nice job describing what I’m trying to achieve in this example. I've done this before, just for a quick-and-dirty template producer. The

How to echo a default value if value not set blade

夙愿已清 提交于 2019-11-29 22:50:00
I would like to know what would be the best way to display a default value if the given value is not set. I have the following in a blade file (I can not guaranty that the key is set, it depends on a multitude of factors). {{ $foo['bar'] }} I would know if the following is the best way to go about it, {{ (isset($foo['bar']) ? $foo['bar'] : 'baz' }} or is there a better way to do this? Thanks :) Use php's null coalesce operator: {{ $variable ?? "Default Message" }} Removed as of Laravel 5.7 With Laravel 4.1-5.6 you could simply do it like this: {{ $variable or "Default Message" }} It's the same

Creating PDF Invoices - Are there any templating solutions? [closed]

拥有回忆 提交于 2019-11-29 21:48:34
Our company is looking to integrate invoices into a new system we are developing. We require a solution to create a layout of the invoice and then convert to pdf. We have considered just laying out the invoice in html/css then converting to pdf. We have also considered using SVG->PDf conversion. Both of these solutions integrate well into our existing templating language used for our web application. Historically we have been a Microsoft based business and used Crystal Reports for such a task but we are looking for an open source Linux solution for this project. Does any one have any