I’m creating a custom theme for micro.blog that I intend to release for others once I’m happy with it. That in mind, is there a way to check if a certain feature is available for a user in a theme template.
Concrete example: I’d like to include a subscribe form partial on certain places in a theme, but only, in the user is on micro.blog premium and has enabled email subscriptions.
I could of course use config.json, which would have something like newsletter_enabled param that user could change, but that would not be “automatic”. Could I check if layouts/newsletter.html file exists and do the magic based on that (or is that template available even when user does not have premium / family plan enabled?)
Update: config.json field for newsletter_enabled kind of worked, but not really. If I set it false as default, let user update the value to true and be done with it, it works on the theme. However, once I do changes to the theme itself (in Github), get the changes and the site rebuilds → the default value of false overwrites the user’s previous change. So that’s not the way, I guess?
What’s the proper way of handling this? Any pointers @manton , @sod, @Mtt ?
Thanks for making a custom theme! What you described in the update should usually work and preserve the user’s config… We’ll have to see why that’s not working.
I think it’s a good idea to add more built-in params to check what a user has access to or which features they’re using. We already have a has_podcasts config, so I think I’ll add a has_newsletters too. (The wording is a little weird there, but going to run with it so it’s consistent.) Then you can do .Params.has_newsletters to see if it’s enabled.
Thanks for making a custom theme! What you described in the update should usually work and preserve the user’s config… We’ll have to see why that’s not working.
My pleasure! Been thinking about doing that for the longest time. Let’s see how that goes, once I got it “shipped” finally (will be a while or two).
Regarding config.json, I’ll check if it keeps happening again. Might be that I just messed something up while pushing updates
I think it’s a good idea to add more built-in params to check what a user has access to or which features they’re using. We already have a has_podcasts config, so I think I’ll add a has_newsletters too. (The wording is a little weird there, but going to run with it so it’s consistent.) Then you can do .Params.has_newsletters to see if it’s enabled.
That sounds like just the thing! Looking forward testing it out later, once it’s available.
Also, not sure if that’s possible, but it would be neat to also have a way to get the newsletter subscribe action URL (or just the newsletter id) for a user (if they have newsletters enabled) in a theme. There’s {{ .Site.RSSLink }} for RSS feed, maybe have something like {{ .Site.NewsletterId }}. With that, I could use it that in partial for the newsletter subcribe form (https://micro.blog/users/subscribe/{{ .Site.NewsletterId }}) or something like that. Alternatively, I can just add a param for the id in config.json
Did you had time to roll out this change? I tried but didn’t seem to get this working yet (no rush, just checking).
Also, not sure if it’s supposed to work this way, but let’s say I have this in my config.json when I update my custom theme in github:
{
"paginate": 20,
"languageCode": "en",
"params": {
"newsletterId": "",
"blogTitle": "Supadupa blog title",
"blogDescription": "My mighty fine blog."
}
}
Now, when I click the “reload / pull” button
…theme files seem to update like they should, except, that if I’ve previously updated config.json manually in theme file editor (for example, I’ve updated newsletterId and blogDescription) → these were now overwritten with the defaults in my custom theme config.json that was just pulled.
I’m probably doing this wrong somehow, am I? As this theme is not used as an “official plugin” yet, I’m not sure if that affects things here?