Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-10-09 19:05:13

Registered: 2019-12-12
Posts: 162

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?

Some possibilities:

A person without knowledge can quickly:

  1. exchange a notice on your website.
  2. exchange featured images on the homepage.
  3. control the “limit” and other attributes of the loops of the entire site.
  4. control the sections you want to display on your homepage.
  5. 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.


#2 2020-10-09 20:39:46

From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: A tab for widgets?

Have a look at how far smd_tabber gets you.

In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links


#3 2020-10-09 20:49:33

From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

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
    • Critical
    • Warning
    • Information

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)

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp


Board footer

Powered by FluxBB