Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
    Chase Wilson

    Hello, I'm trying to make a macro with a default argument, but I get an error

    {% macro highlight_scripts(languages=["rust", "ini"]) %}
    {% endmacro highlight_scripts %}
    * Failed to parse "templates\\macros.html"
     --> 6:38
    6 | {% macro highlight_scripts(languages=["rust", "ini"]) %}␊
      |                                      ^---
      = expected an integer, a float, a string, or `true` or `false`

    Can macros not support all literal types?

    Chase Wilson
    And is there a way to construct null values / what's the best way to do optional macro params
    1 reply
    Fabian Würfl
    Is it possible to call rust functions from within the templates? (currently calling {{ my_object.some_function() }} results in a template error :/)
    1 reply

    I've got a data structure that looks like this:

    {"headers":["Filename"," Duration"],"records":[["hbs001-wie-kamen-die-wolken-zu-ihren-namen.mp3","0:07:45.214694"],["hbs001-wie-kamen-die-wolken-zu-ihren-namen.opus","0:07:45.180583"],["hbs002-der-blitz.mp3","0:08:58.044082"],["hbs002-der-blitz.opus","0:08:58.008500"],["hbs002-die-farben-des-himmels.mp3","0:11:41.152653"],["hbs002-die-farben-des-himmels.opus","0:11:41.111938"],["hbs003-wie-entsteht-regen.mp3","0:12:04.741224"],["hbs003-wie-entsteht-regen.opus","0:12:04.720833"],["hbs004-der-regenbogen.mp3","0:08:19.591837"],["hbs004-der-regenbogen.opus","0:08:19.547833"],["hbs005-wie-schwer-ist-luft.mp3","0:10:22.471837"],["hbs005-wie-schwer-ist-luft.opus","0:10:22.431438"],["hbs006-der-luftdruck-und-das-wetter.mp3","0:08:09.952653"],["hbs006-der-luftdruck-und-das-wetter.opus","0:08:09.910458"],["hbs007-der-geruch-des-regens.mp3","0:06:58.089796"],["hbs007-der-geruch-des-regens.opus","0:06:58.052604"],["hbs008-der-blitz.mp3","0:08:48.248163"],["hbs008-der-blitz.opus","0:08:48.207313"],["hbs009-das-gerausch-des-gewitters.mp3","0:07:10.654694"],["hbs009-das-geräusch-des-gewitters.mp3","0:07:10.654694"],["hbs009-das-gerausch-des-gewitters.opus","0:07:10.634167"],["hbs009-das-geräusch-des-gewitters.opus","0:07:10.634167"],["hbs010-der-jetstream.mp3","0:08:17.841633"],["hbs010-der-jetstream.opus","0:08:17.805500"]]}

    How do I select a Duration by Filename? I tried around a lot with filter but it doesn't seem to work for me because it expects a Vec.

    2 replies
    Help me because I have an urgent matter and a simple problem for someone experienced but I am just getting started with Actix with Tera and Rust. Tell me what to do when I copied this example
    I created a sample page.html file in the templates directory and in index.html file I added a menu and css file, in the menu I have link to the href = "page.html" file and of course css does not work and is correctly added and page.html does not open. CSS is correctly added because when I open index in browser CSS and menu works only when I start Actix it doesn't work :/ How to correctly add to Actix with Tera CSS and another HTML page to generate them correctly? Please show small example based on link from GitHub how I can correctly add CSS and another page in html.
    In dependencies I have lastest crates.
    2 replies
    Hello people! Is there a way to get more detailed information on why a template failed?
    Nevermind, I was being stupid!
    1 reply
    John Meow
    Is there a way to make this shorter?
    {% if var %}{{var}}{% else %}default{% endif %}
    Something like bash
    1 reply
    Hey, I wanted to integrate Tera with a custom web server, is there a guide for that? I haven't checkout Tera's internals yet
    1 reply
    Vitaly Olegovich
    Hi, I have to to get values from an HashMap inside a loop inside a Tera template, what I have tried to do so far is
    {{ packages_label_map | get(key=guarantee.slug) }}
    But it doesn't work. What am I doing wrong?
    1 reply
    please how can i use extended css in html file with tera
    1 reply
    Andre Brisco
    Is there some documentation that enumerates the differences between tera and jinja2?
    1 reply
    Dmytro Polunin
    Hello. I have 10 ms for rendering simple page with 10-20 posts with title, ~100 symbols for post preview. Will I have time to generate it with the help of tera?
    1 reply
    John Meow
    Can I use if-else in macro invocation? Something like
    {% macros::mymacro({% if number %}{{ number }}{% else %}42{% endif %}) %}
    1 reply
    David James
    Does Tera support a way to lookup a string key in a map?
    2 replies
    Hey all, does tera have a way to render a bytes template? For example a template which is a Vec<u8> or &[u8]
    2 replies
    Mateus Amin

    Does Tera have features that make it HTML5 specific? Would it be appropriate to use it for markdown or text templating?

    Taking a step back I am writing a cli (and later gui) that takes input to produce a text/md document. Looking at a possible rust (then flutter) implementation. I already use Zola and thanks to that am looking at Tera. Open to suggestions.

    Thanks in advance.

    9 replies
    Andreas Pfeil

    Hi, I am trying to access the tera context values, but for some reason it does not work. I think the issue might be that the values contain dots. I tried for example this one: __tera_context.values["action_skills.skill0.points"] but it says

    Error: Variable `__tera_context.values["action_skills.skill0.points"]` not found in context while rendering 'macros': the evaluated version was `__tera_context.values.action_skills.skill0.points`. Maybe the index is out of bounds?"

    (I am using tera with rocket).

    The only way I can access them is {% for key, value in values %}, but this is a bit much just to get a single value... I already tried escaping the dots with a backslash, but no success so far. Any ideas what I am doing wrong?

    1 reply
    Hi folks,
    how can I loop over some Json data that look like this ?
    {"a":"va1", "b":"vb2"}
    {"a":"va2", "b":"vb2"}
    So how does one add CSS to the .tera files?
    I have it added like normal html would but it doesnt see it i guess.