Closed markokocic closed 2 years ago
Hi @markokocic, thanks for taking the time to open this issue. If I get it correctly, I think we might already have such feature, it's just not really documented yet 😞. Let me know if this is what you're looking for:
You can use the :template-vars
parameter in the (weblorg-site)
function. Those variables will be available to all the templates for your website. (the same parameter can be passed to weblorg-route
as well, but I'm not including an example because you seemed to be looking for the global version 😄)
(weblorg-site
:theme #'weblorg-theme-autodoc
:template-vars '(("project_name" . "'templatel")
("project_github" . "https://github.com/clarete/templatel")
("project_description" . "A modern templating language for Emacs-Lisp")))
The autodoc
theme of weblorg actually currently requires some variables to be defined right in its base.html
template, so I thought it'd definitely be nice to have such mechanism.
Please let me know if that's what you're looking for! If not, it'd be nice if you could give some examples of how you'd want your publish.el
to look like! Thank you 🙇🏾
Hi @clarete, that's exactly what I was asking for. I created a ticket since I didn't find anything in the docs.
oh nice; I might re-open the ticket to remind my self to add that to the docs! thank you 🙇🏾
@clarete in this case should I repeat :site
for every route? What about a weblorg-default-template-vars
variable like the one we have for the base URL weblorg-default-url
?
Hi @semente 👋🏾 this is a pretty good question, and the answer is, unfortunately: it depends 😄 these are the general rules:
when called without :base-url
, a call to weblorg-site
will use weblorg-default-url
as a default. and if you call weblorg-route
without passing :site
it will do a lookup in the weblorg--sites
hashtable using weblorg-default-url
. So, if you only have one domain for your website, I recommend the following:
(setq weblorg-default-url "https://your-website.yay")
;; notice we're not passing `:base-url'
(weblorg-site
:theme #'weblorg-theme-default ;; set to nil you want to use weblorg-copy-static and not have any inherited theme file included
:template-vars '(("system" . "debian")))
All the calls to (weblorg-route)
that don't receive a :site
parameter are going to share that configuration because of weblorg-default-url
The reason we have this weird mechanism is to allow routes to be in different domains. My use case was hosting static assets in a CDN. That way you could use the above settings for most of the site and then have just your assets route to use a different :site
, e.g.:
(weblorg-copy-static
;; .. fill in with the asset parameter
:site (weblorg-site :base-url "https://cdn.your-website.yay"))
Although we're paying the complexity price for this feature, I think we still have to add some support for the lookup of addresses in different sites in url_for
for that to be really useful.
Got it! And what you suggested works! Thanks
This issue seems resolved, might wanna close it.
It would be nice to have an option to have a site wide config file where one can add custom parameters, config options that can later be used as variables inside templates.