Textpattern CMS support forum
- Registered: 2019-12-12
- Posts: 108
A tab for widgets?
Continuing my other topic where it talks about a tab for static pages, I wanted to give a suggestion for another tab: widgets.
With ease we developers can change things directly in the forms, be it a slide of images, simple text or anything else. But at the moment, many influencers, physical stores and etc., want to have their own website, and we cannot demand that these people have such knowledge, or else, that they hire a developer whenever they need to exchange a simple text. And for sure you, the developer, wouldn’t want the customer to go there and spoil something, huh?
A person without knowledge can quickly:
- exchange a notice on your website.
- exchange featured images on the homepage.
- control the “limit” and other attributes of the loops of the entire site.
- control the sections you want to display on your homepage.
- control your sidebar by adding other widgets (which can be shortcodes made by the creators of the theme).
I just gave you some ideas. If I keep thinking I will go far. It is something that in my opinion is very useful. I leave this suggestion to you, I hope it will be useful to help you think.
Re: A tab for widgets?
I’ll start with this one because it’s easier. Take a look at the adi_variables plugin. That adds a nice tab where you / admins can define and edit any variables via a UI. These become
<txp:variables> in their own right automatically, and therefore are usable throughout your site templates for any and all purposes.
Control the limit? Set a variable called
article_limit and use it in your
<txp:article limit='<txp:variable name="article_limit" />' /> tags. Then they all change if anyone alters that value from the Variables tab.
Yes, they’re all text fields so if you want to set up a ‘list of sections to display’ then you need to kind of know what sections are in use so you can list them in your “site_sections” variable field, but it’s better than having to hunt through forms to change things. Alternatively, Adi is to the rescue yet again with adi_menu, which is an incredibly powerful way of building menus and faux section/categories like WordPress does.
Regarding notices, I’ve done this (very successfully) on client sites via use of Sticky article status. Basically, you create an article in any section, set its status to ‘sticky’ and then in your template:
<txp:hide> Load any banner on the page </txp:hide> <txp:article status="sticky" form="announcement" wraptag="section" class="banner" /> ... more page furniture... <txp:hide> Show regular article content </txp:hide> <txp:article />
If the sticky article isn’t defined for that section (or is set to status=hidden), no banner is shown. This way, customers can define their own notifications on a per-section basis and, crucially, can alter their own content – which is something that a few user levels can’t do if you were to do this in forms. I’ve also set up a category tree like this:
- Alert level
Inside the ‘announcement’ form, it checks this category (if set) and adds a class with the same name as the category name to the content. Thus CSS can target this class to control whether the announcement is ‘red alert’ (e.g. we’re closed due to covid) or just informational. All content creators need to do is be told to pick the relevant category from Category 1 in their Sticky articles to change how severe the notice is in that section.
For the homepage, you can set up something similar but since the homepage has no section of its own, you need to define a ‘dummy’ section (such as “snippets”) and set it to have no Page/Stylesheet (i.e. pageless). Assign your announcement article to that section with a sticky status and ensure your default page template uses the same kind of construct as above to add it to the page, but just use a
<txp:article_custom section="snippets" /> tag instead.
Hope some of that gives you ideas.
Last edited by Bloke (2020-10-09 20:53:11)