-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
passing variable to a template #1
Comments
This happens on the Haskell side of things; you need to pass context variables in when calling let contextLookup varName =
case varName of
"username" -> toGVal username
"imageURL" -> toGVal imageURL
_ -> def -- def for GVal is equivalent to a NULL value
context = makeContext contextLookup
htmlSource $ runGinger context template Alternatively, you can write your context object as any dictionary-like data type that has a |
This should probably be fixed in the documentation. |
Is there any way to create a parent/child template? |
Sure. You have two options here:
For example, you might write a parent template like so: <!DOCTYPE html>
<html>
<head>
<title>{% block title %}My Super Fun Site{% endblock %}</title>
</head>
<body>
<header>My Super Fun Site</header>
<main>
<h1>{% block main_header %}Hello!{% endblock %}</h1>
{% block content %}
{% endblock %}
</main>
<footer>
Copyright (c) 2017 myself. All Rights Reserved.
</footer>
</body>
</html> And then you can have a child template that overrides some of these blocks: {% extends 'master.html' %}
{%- block title %}This is a different title.{% endblock -%}
{%- block content %}
Lorem ipsum dolor sit amet adipiscing elit. And so on.
{% endblock -%} This will render a page using the same structure as the master template, but overriding the In order for this to work correctly, you need to tell the template loader how to load the parent template; the CLI contained in the main repo demonstrates this; you need to pass an Hope that clears things up. |
thanks, I'll try. |
how is your library better compared to https://github.com/sourrust/karver ? |
@tdammers up |
Well, the most important differences should be obvious (ish) from the API and its types; anyway, from what I can gather from Karver's documentation, here's a (probably incomplete) list of what Ginger does differently (though whether that is necessarily better is debatable and depends on priorities and context):
The only real problem I see with Karver is that it uses Hope that clears things up a little. |
thanks. |
Is there a MVP of returning an html file to a client? in this code, how is "index.html", assuming that's the name of an html file, supposed to be passed to it?
|
that's not a library, but a pain. part of code here, part there, setup this, adjust that. how to run it after all? in the documentation -- nothing. in https://github.com/sourrust/karver everything is comprehensible. |
This is a library that I maintain and publish for free; you can use it in
any way you see fit, or you can choose not to use it. I am also very open
to suggestions, constructive criticism, and so on; I do not, however,
respond to rants, demands, or vague unconstructive bashing.
If you feel that Ginger lacks in certain areas, which by the way is totally
possible, if not expected, then you have a few options at your disposal:
1. Fix the problem yourself, send patches, and I will be happy to merge
them (or else explain patiently why not)
2. Don't use Ginger. I'm fine with that, and nobody is putting any pressure
on you. If Karver works better for you, then use that, no hard feelings
whatsoever.
3. Pay me, or someone else, to fix things. I'm providing Ginger as-is, and
I'm willing to put some effort into making it easier and better for
everyone, but if you want me to do requests, then the amount of pro bono
work I will do is limited.
4. Make more concrete and constructive suggestions. If you can show me what
you think an example program should look like, I will be more than happy to
discuss the possibilities. Likewise, if you can suggest what the
documentation on ginger.tobiasdammers.nl should look like, I will be happy
to make adjustments. Btw., the guide section on that website comes directly
from yhe ginger repo itself, so you can even issue pull requests.
Whatever you do, however, I kindly ask you to refrain from accusations and
between-the-lines insults ("painful"). Please do not raise issues just to
vent your frustration, it's just not constructive.
All that said: Ginger is a lot more generic than Karver, making it suitable
for a wider range of applications. This flexibility comes at a cost, in the
form of a more complex interface and pretty wild type signatures. I tried
to make things as palatable as possible, and I certainly haven't achieved
an optimum yet, and since I don't have infinite amounts of time, any help
is welcome. Either way though, if Karver meets your use case, then Ginger
is most likely overkill. It's up to you to judge that.
Hope that helps.
…On May 3, 2017 5:45 PM, "Alex Maslakov" ***@***.***> wrote:
that's not a library, but a pain. part of code here, part there, setup
this, adjust that. how to run it after all? in the documentation -- nothing.
in https://github.com/sourrust/karver everything is comprehensible.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABXjx9uFbAOWsu-Ljq_ycLCl634ukdR0ks5r2KEsgaJpZM4Mie0o>
.
|
Also, this has long gone beyond the scope of "how am I supposed to pass these variables -- title, naviagation, body -- to this template?", so I'm closing this. |
from the documentation:
how am I supposed to pass these variables -- title, naviagation, body -- to this template?
The text was updated successfully, but these errors were encountered: