by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:40
    djc commented #337
  • 04:19
    jmafc commented #337
  • 04:18
    jmafc commented #337
  • 04:18
    jmafc commented #337
  • Jun 03 20:02

    djc on master

    Reorder parser type definitions (compare)

  • Jun 03 19:47

    djc on master

    Revert whitespace matching to o… (compare)

  • Jun 03 19:41
    djc commented #337
  • Jun 03 19:41
    djc commented #337
  • Jun 03 19:39
    djc closed #337
  • Jun 03 19:39

    djc on master

    Strip 0 or more instead of 1 wh… (compare)

  • Jun 03 19:20
    jmafc opened #337
  • Jun 03 18:56
    djc commented #336
  • Jun 03 18:56

    delete-merged-branch[bot] on deep-blocks

    (compare)

  • Jun 03 18:56
    djc closed #335
  • Jun 03 18:56

    djc on master

    Refactor code for finding neste… Allow block definitions in if/f… (compare)

  • Jun 03 18:56
    djc closed #336
  • Jun 03 18:55
    jmafc commented #336
  • Jun 03 13:47
    djc commented #336
  • Jun 03 13:42
    jmafc commented #336
  • Jun 03 11:30
    djc commented #336
Dirkjan Ochtman
@djc
But that's outside the scope of Askama
Sayan Nandan
@sntdevco
Right, got it
qoh
@qoh
Is there any way to match on constructed tuples? I have 'previous page' and 'next page' hrefs in Options and would like to omit the outer element containing pagination when both are None, while avoiding a manual double check a la prev.is_some() || next.is_some().
Mehmet ERİBOL
@mehmeteribol_gitlab
i am using tera template engine. It has context type with holding data. Is there some similar for askama too?
Dirkjan Ochtman
@djc
Can you give an example of what that looks like?
Mehmet ERİBOL
@mehmeteribol_gitlab
let mut context = tera::Context::new();
context.insert("error", &"wron type");
let s = template.render(&"login.html", &context);
Dirkjan Ochtman
@djc
Have you looked at Askama's documentation at all?
It is built around context type definitions
Mehmet ERİBOL
@mehmeteribol_gitlab
yes i did but it does not look like the same. I can use a struct for askama but it seems, for every template render, have to use a different struct. I am just saying, a HashMap like type can be good. But nevermind, i am a noob, probably missing somethings.
Dirkjan Ochtman
@djc
template rendering takes a reference to your context type
so you could reuse the same struct for each render
Henk van der Laan
@helaan
Hmm, I noticed Askama 0.9 is out, but I can't find a changelog in the Github Releases.
Also, is this chat bridged to Matrix somewhere?
Dirkjan Ochtman
@djc
Sorry, I haven't written up release notes yet
Will do that tomorrow
I haven't set up a Matrix bridge
Dirkjan Ochtman
@djc
Henk van der Laan
@helaan
Thanks for the release notes, looks good. Matrix.org provides a Gitter bridge, that may be easier to set up and maintain (and as this chat is public, having messages flow through them may be less of a concern)
Dirkjan Ochtman
@djc
I'm not really motivated to do something about that
JJBordy
@JJBordy
Hey, any idea what might cause this error?
error[E0308]: mismatched types
 --> src/pecum/public_handlers/signup.rs:8:10
  |
8 | #[derive(Template)]
  |          ^^^^^^^^
  |          |
  |          expected struct `std::string::String`, found `&str`
  |          help: try using a conversion method: `Template.to_string()`
Dirkjan Ochtman
@djc
Not sure
Can you show me the struct definition and the template?
JJBordy
@JJBordy

the template struct its self is:

#[derive(Template)]
#[template(path = "public/signup.html")]
struct Signup<'a> {
    vd: view_data::ViewData<'a>,
}

and the template part causing this error is this: (all the data inside is either bool (append), &'a str, String, Vec<String> or other structs which have String and Vec<String>); I also try to pass arguments to javascript functions (preiaInsert, askPreiaDelete); the functions which end with _js -> return a stringified array ("[a,b,]")

<div class="dropdown">
    <button class="dropdown-toggle rcpreia" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        {{preia_config.label}}
    </button>

    {% let append = preia_config.append %}
    {% let insert_keys = preia_config.insert_keys_js() %}

    {% let editable -%}
    {% let editable_db_col -%}
    {% let editable_add_name -%}
    {% let editable_name_keys -%}

    {% match preia_config.ed_model_src %}
        {% when Some with (source_editable) %}
            {% let editable = true %}
            {% let editable_db_col = source_editable.db_col %}
            {% let editable_add_name = source_editable.additional_name %}
            {% let editable_name_keys = source_editable.name_keys_js() -%}
        {% when None %}
            {% let editable = false -%}
            {% let editable_db_col = "" -%}
            {% let editable_add_name = false -%}
            {% let editable_name_keys = "" -%}
    {% endmatch %}

    <div class="dropdown-menu">

        {% for opt in preia_config.admin_options %}
                <!-- can delete only if source editable -->
            <a class="dropdown-item"
                {% if editable %}
                    oncontextmenu="askPreiaDelete({{editable_db_col}}, {{opt.id}}, {{true}}, {{opt.name}})"
                {% endif %}
                    onclick="preiaInsert({{insert_keys}}, {{opt.values_js()}}, {{append}})">{{opt.name}}</a>
        {% endfor %}


        {% for opt in preia_config.user_options %}
                <!-- can delete only if source editable -->
            <a class="dropdown-item"
                {% if editable %}
                    oncontextmenu="askPreiaDelete({{editable_db_col}}, {{opt.id}}, {{false}}, {{opt.name}})"
                {% endif %}
                    onclick="preiaInsert({{insert_keys}}, {{opt.values_js()}}, {{append}})">{{opt.name}}</a>
        {% endfor %}

        <div class="dropdown-divider"></div>

        {% if editable %}
            <div class="dropdown-divider"></div>

            {% if editable_add_name %}
                <a class="dropdown-item text text-success"
                    onclick="askPreiaAddElement({{editable_db_col}}, {{insert_keys}},{{editable_name_keys}})">
                    <small>[add]</small></a>
            {% else %}
                <a class="dropdown-item text text-success"
                    onclick="preiaAddElement(false, {{editable_db_col}}, {{insert_keys}},{{editable_name_keys}})">
                    <small>[add]</small></a>
            {% endif %}
        {% endif %}

    </div>
</div>
Dirkjan Ochtman
@djc
Maybe open a GitHub issue
But this template refers to a preia_config variable that doesn't appear in the type definition
JJBordy
@JJBordy
I have a lot of structures/templates, it's too much to write them here; preia_config is passed from another template; will narrow down to the single thing that causes the error and post it here;
Dirkjan Ochtman
@djc
Thanks
I recommend using the print attribute to print the relevant code generated for templates and paste that in your source files
Then the compiler will point exactly at the place that is causing the problem in the generated code
JJBordy
@JJBordy

I think the problem is that I let a variable be one time &str and another time String; so maybe it gets confused; is there a way to initialize a variable to String?

{% let my_str = String::new() %}
<!--  or -->
{% let my_str = std::string::String::new() %}

it says unable to parse template whenever I try one of this ways

Dirkjan Ochtman
@djc
Not sure
You should really file an issue so I can have a look
JJBordy
@JJBordy
I ended up converting Strings to str; but here's the issue: djc/askama#311
vietlib
@vietlib
Hi my app return json httpresponder, how can i or any example on displaying json ?
Dirkjan Ochtman
@djc
There's a JSON filter you can use
You have to enable it first through a feature though
Norbert Kéri
@norbertkeri
hey, is there a way to pass iterators to templates?
does anyone have a working example?
Dirkjan Ochtman
@djc
It should work, it's just tricky
I think the principle is that if a &T implements Into Iterator, it should work in a for block
But I was just yesterday trying to improve this
It's complex because it really needs specialization to work well, which of course isn't on stable Rust yet
Norbert Kéri
@norbertkeri
I'm trying to iterate over a btreemap in reverse, so I already have an iterator
I'm not sure how to create an "already reversed btreemap" that I could pass into the template so the template can call .into_iter() on it
Norbert Kéri
@norbertkeri
also, is there a way to create enum variants in a template? I would like to have type safe links, so I created an enum with all the links on my site
using {{ PageLink::Homepage }} in a template is fine, but if the variant has members, it fails to parse the template, eg {{ PageLink::ArticleById("hello world") }} fails to parse
Dirkjan Ochtman
@djc
There is a match block
Norbert Kéri
@norbertkeri
can you show me an example of how would I iterate over a btreemap in reverse in a template?