Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Alice Carroll
    @iamalicecarroll
    Something like bash
    ${var:-default}
    1 reply
    weegee
    @Daksh14
    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
    @VitalyOlegovic
    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
    xi6th
    @xi6th
    please how can i use extended css in html file with tera
    1 reply
    Andre Brisco
    @UebelAndre_gitlab
    Is there some documentation that enumerates the differences between tera and jinja2?
    1 reply
    Dmytro Polunin
    @p0lunin
    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
    Alice Carroll
    @iamalicecarroll
    Can I use if-else in macro invocation? Something like
    {% macros::mymacro({% if number %}{{ number }}{% else %}42{% endif %}) %}
    1 reply
    David James
    @xpe
    Does Tera support a way to lookup a string key in a map?
    2 replies
    Emmanuel Thompson
    @sharksforarms
    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
    @MateusAmin

    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
    @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
    ngirard
    @ngirard:matrix.org
    [m]
    Hi folks,
    how can I loop over some Json data that look like this ?
    {"a":"va1", "b":"vb2"}
    {"a":"va2", "b":"vb2"}
    cowboy8625
    @cowboy8625:matrix.org
    [m]
    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.
    ngirard
    @ngirard:matrix.org
    [m]
    Hey Thomas, too bad you suppressed your answer, because I could still take advantage of it !
    1 reply
    Thanks Thomas, much appreciated !
    ngirard
    @ngirard:matrix.org
    [m]
    Thomas the problem is that the data I was dealing with don't come with a "parent" — the "products" in your own lines
    manotrix
    @manotrix:matrix.org
    [m]
    How do I format numbers in templates in general and specifically BigDecimal?
    manotrix
    @manotrix:matrix.org
    [m]
    I was able to get a basic format by doing value | float | round(precision=2) is there a better way?
    Hemanth Bollamreddi
    @blmhemu
    Hey ! How do I convert a month number to month name. Something like {{ 12 | month }} which would print "December" ?
    1 reply
    manotrix
    @manotrix:matrix.org
    [m]
    To elaborate, assuming your 12 is coming from a variable {{ "2020-" ~ yourvariable ~ "-01" | date(format="%B") }}
    kiiyuh
    @kiiyuh:matrix.org
    [m]

    I'm trying to do a navbar and apply the "active" class to the currently selected page. For that, I found this approach: https://stackoverflow.com/questions/18600031/changing-the-active-class-of-a-link-with-the-twitter-bootstrap-css-in-python-fla

    But with Tera I get the following error:

    4 |     ('/', 'index', 'Home'),␊
      |      ^---
      = expected an expression
    kiiyuh
    @kiiyuh:matrix.org
    [m]
    I instead just give navigation_bar as a parameter to the template itself from Rust now, that worked. But it's not as neat now :/

    However, a new issue emerges. Now I get

    Variable active_page not found in context while rendering "index".

    I assume the following works in Jinja, but not in Tera. So the base template expects active_page to be set, but it gets set only later. Swapping the order of extends and set results in yet another error though :/

    {% extends "base" %}
    {% set active_page = "index" %}
    kiiyuh
    @kiiyuh:matrix.org
    [m]
    Just moving the whole thing into Rust code solved it.
    Tanay Pingalkar
    @tanay-pingalkar
    hello, how to add css to tera/rocket
    Mitchell Hynes
    @ecumene
    Has anyone used Tera via WASI FS? If so, have any of you found any issues?

    When I write:

        let entries = std::fs::read_dir("templates")?
            .map(|res| res.map(|e| e.path()))
            .collect::<Result<Vec<_>, std::io::Error>>()?;

    I get

    ["templates/base.html"]

    But, when I do render via:

        match tera.render("base.html", &context) {
            Ok(result) => println!("{}", result),
            Err(err) => eprintln!("{}", err),
        }

    I get Template 'base.html' not found

    I'm mounting ./site/templates on host to ./templates in guest via Wasmtime
    Okay, never mind. It works now, but only if it has access to the directory ./templates is in too. I'll make an issue!
    Mitchell Hynes
    @ecumene
    James Kerr
    @disconsented

    Pretty quiet, but I figure this is worth asking about:

    Is there a sensible way to style content using a CSS framework like bulma without shortcodes? I think the answer is no, tera and commonmark seem to expect you to write the HTML yourself

    Felix Wiegand
    @fxwiegand_gitlab
    Hello, has anyone experienced this kind of error? UTF-8 conversion error occured while rendering template: converting rendered buffer to string Would be happy for any kind of advice! Thanks guys!
    Andrew Wheeler(Genusis)
    @genusistimelord
    hello
    did you have some sort of Weird Unicode character that could not be transformed into utf8?
    it would be nice to see an Example of the template throwing the said error as that would help diagnose the issue.
    Abhinav Marwaha
    @abhinav_marwaha_twitter
    How to add custom rust functions in tera?
    Andrew Wheeler(Genusis)
    @genusistimelord
    asking for Rocket? or Tera directly?
    Andrew Wheeler(Genusis)
    @genusistimelord
    In Tera Directly you would create a Function that return a Result<Value>. However If you want this function to use a outside Variable Lets say you have a hashmap of URL's then you need to make a fn that returns a Function type which is a Boxed closure that has a return of Result<Value>
    Andrew Wheeler(Genusis)
    @genusistimelord
    here is an example of make_url passing a hashmap of known urls to a closure that is returns as a Boxed Value.
    when you add this function you must use a hashmap for the closures Args and within tera the function arguments can be optionally defined but must be written if required by you
    so in the above example within Tera to use this i would do
    {{ url_for(name='home') }} and it should change this into http://address.com/home within the tera document or Emit a Error if it did not Exist. I would avoid unwrap as much as possible and map them to actual Errors so it is easier to debug even in release.
    Andrew Wheeler(Genusis)
    @genusistimelord
    For Rocket you would do the Same But based on the Version of Rocket you will need to gain access to its Tera structure and then call the add function onto that.
    Craig Kaiser
    @knation4:matrix.org
    [m]
    Hi all, I hope this is an easy question. If I am looking to grab the value
    for "humans" from my context, how would I that? I have tried the following:
    console.log({{__tera_context}})
    
    {
      "humans": [
        {...}
      ]
    }
    console.log({{humans}})
    
    Variable `humans` not found in context while rendering 'index'
    console.log({{__tera_context.humans}})
    
    Variable `__tera_context['humans']` not found in context while rendering 'index': the evaluated version was `__tera_context."humans"`. Maybe the index is out of bounds?
    Paul Delafosse
    @oknozor

    Hey I am writing some markdown changelog templates that look like this :

    {% for type, typed_commits in commits | sort(attribute="type")| group_by(attribute="type")%}                            \
                                                                                                                            \
    #### {{ type | upper_first }}
                                                                                                                            \
        {% for scope, scoped_commits in typed_commits | group_by(attribute="scope") %}                                      \
            {% for commit in scoped_commits | sort(attribute="scope") %}                                                    \
                {% if commit.author %}                                                                                      \
                    {% set author = "@" ~ commit.author %}                                                                  \
                {% else %}                                                                                                  \
                    {% set author = commit.signature %}                                                                     \
                {% endif %}                                                                                                 \
                - {{ commit.id }} - **({{ scope }})** {{ commit.summary }} - {{ author }}
            {% endfor %}                                                                                                    \
        {% endfor %}                                                                                                        \
        {% for commit in typed_commits | unscoped %}                                                                        \
            {% if commit.author %}                                                                                          \
                {% set author = "@" ~ commit.author %}                                                                      \
            {% else %}                                                                                                      \
                {% set author = commit.signature %}                                                                         \
            {% endif %}                                                                                                     \
                - {{ commit.id }} - {{ commit.summary }} - {{ author }}
        {% endfor %}                                                                                                        \
    {% endfor %}                                                                                                            \

    It's a bit anoying that I need to escape every single carriage return with \\. Wondering if there is a way to do this implicitly ?

    first name last name
    @igitter_gitlab
    How can I implement a display() function or else for a custom struct so that I can just print the instance of a struct in a template like {{ my_custom_struct }}?
    Eduard Tolosa
    @Edu4rdSHL

    Hello, I have the following problem:

    My editor has a 120 characters limit for columns, however one of my tera lines has >120 chars. As one part of the line gets in another line, Tera is putting the new line as expected, is there a way to escape that? Like you use \ on bash. I have tried \ but didn't worked

    I want something like

    set [ find default-name={{interface.name}} ] comment={{interface.comment}} l2mtu={{interface.l2mtu}} \
        mtu={{interface.mtu}}

    that acts as set [ find default-name={{interface.name}} ] comment={{interface.comment}} l2mtu={{interface.l2mtu}} mtu={{interface.mtu}}

    Eduard Tolosa
    @Edu4rdSHL
    It's the Tera vscode extension causing it, uuuh