Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-08-24 16:25:17

zero
Member
From: Lancashire
Registered: 2004-04-19
Posts: 1,349
Website

Including assets in themes

When making a theme, I found the easiest way is to include site-design images and fonts in their own folders within the theme style folder. The user doesn’t have to upload them via the content images panel. A short link to them in the stylesheet suffices. There are less instructions needed.

Is there a way to do this with plugins? Can they be somewhere in the theme and ready to be made active by the user? Or even activated?

Also, how about article#2? The theme may not be at all compatible with the in-built article, so if another article could be included with the theme, it could be designed to suit the theme. This also leads to custom fields, categories and sections. Is it way beyond present capabilities to include any of these?


Wondrous Healing Wondrous ways to a healthy old age
Safe Reiki Harmless natural healing.
Gud One Blog

Offline

#2 2020-08-24 16:42:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,718
Website

Re: Including assets in themes

As I mentioned elsewhere as our posts crossed you can put assets wherever you like, though I would keep them out of the directories that core expects to contain specific assets.

For plugins, currently, the short answer is no. You can bundle recommended plugins in subdirs within your theme for distribution but people need to install them by hand; there’s no way to ‘autoload’ them1. Same with other assets like sections and categories and prefs. It’s not currently possible out of the box without some PHP code glue to “bootstrap” your theme.

Txp has the capability to autoload any type of content except images and files – even plugin data – via XML config files like those found in the /setup area. It’s just that we haven’t exposed this ability outside of the setup system just yet while we refine it and make it ready for the big time.

In any case, I would strongly recommend NOT adding Sections to Txp and/or linking your theme assets with them on installation. It’s tempting to do that to cut down on manual steps, but it can cause some seriously unwanted behaviour or data loss. Same with plugins, to a degree. What if you install a theme and it overwrites an existing plugin on a live site and it’s not compatible with your current usage, or Txp, or has different attributes?

The approach we took with our theme was to use plugins as progressive enhancement. Use <txp:if_plugin name="abc_whatever" version="x.y.z"> wrappers in your code to do something if the plugin is there, and to fallback on ‘worst case’ or ‘workable solution’ if it isn’t.

1 Well, you can from 4.8.2+ (I’ve done it in a theme) but it requires some PHP trickery.

Last edited by Bloke (2020-08-24 16:48:00)


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

Offline

#3 2020-08-24 16:50:18

zero
Member
From: Lancashire
Registered: 2004-04-19
Posts: 1,349
Website

Re: Including assets in themes

Thanks for explaining all that, it all makes sense. Installing plugins is very easy anyway. But I’ve often been surprised by what Textpattern is capable of that I have overlooked. Keep up the good work.


Wondrous Healing Wondrous ways to a healthy old age
Safe Reiki Harmless natural healing.
Gud One Blog

Offline

#4 2020-08-24 16:58:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,718
Website

Re: Including assets in themes

Thanks. I did sneak in some code changes to 4.8.2 specifically so bootstrap-type plugins could exist in a theme and do all manner of wonderful autoloading and updating. And it works supremely well. It’s just not publicized yet because it’d be nice to have an official way to do this.

Part of the plan in making this an official way to manage theme assets is in the way plugins are managed and installed. That’s changing big time in 4.9 and a chunk of the work is already done so we can ultimately take compatibility info into account and show additional data bundles and offer plugin upgrade notifications and so forth.

When we figure out how to selectively upload content from a plugin, that concept is directly transferrable to themes (though it’s slightly more complicated when syncing via the import/export feature). At that point, we’ll be in a position to allow bundles of content to be offered and have people opt-in to having them installed when a theme is installed.

Anyway, when we release our theme, you’ll be able to see the bootstrap in action. It is pretty neat, even if I do say so myself :)


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

Offline

Board footer

Powered by FluxBB