package-info.xml: how to handle different templates for default and core?

Started by Deprecated, January 30, 2014, 03:53:18 PM

Previous topic - Next topic

Deprecated

I started with the same template file:

<require-file name="MyModification.template.php" destination="$themedir" />

Somewhere along the way I realized (duh!) that default and core may be or can be incompatible (depending on exactly what you're doing).

Two ways I can handle this:

1. Same template file but with some way to tell if it's running default or core. This is vastly preferable because if my template file just knew which theme it was running under a small code test could cause it to emit the right HTML format.

2. Different template files to be installed in the separate theme directories. If this version, I presume I put each theme template in a separate directory in my mod package? e.g.:

<require-file name="core/MyModification.template.php" destination="Themes/core" />
<require-file name="default/MyModification.template.php" destination="Themes/default" />


I suspect the format above is not quite right but it's a first stab, and I figure it's easier to ask and be told the correct way rather than finding out by trial and error, and then come up with some Mickey Mouse way that works but isn't correct.

I'll appreciate your help, thank you!


JBlaze

You can work around it by using the $boarddir variable.

<require-file name="core/Some.template.php" destination="$boarddir/Themes/core" />

There really is no other way to do it. However, you may have problems if the theme does not exist, and I'm not sure of any element in the XML that allows bypassing of the error.[/code]
Jason Clemons
Former Team Member 2009 - 2012

Deprecated

Thanks Blaze! I used to knew that before I forgot it. Been about 3-4 years since I been writing SMF code! Some of my mods even use that.


As a follow-up question:

I'm referring to selection buttons or tabs just above my content to pick different views of my content. I have a third method I can provide selection of content views that's compatible for both core and default (but looks old fashioned). Would it be a good idea to emit this version of the HTML if the theme is neither core nor default? Or provide a selection checkbox in my mod configuration to select this if somebody's them is not compatible with either default or core?

BTW FWIW I'm using the new integration hooks. Don't know if that matters or not.

Deprecated

I left my house shortly after posting the reply and on my way to a doctor's appointment I realized several things.

Of course you can tell what theme is loaded. SMF has to know what theme to load and it's stored in the settings. All I have to do is dig into the code or the database and it'll be easy to find. Once found, I can use that to choose which style of buttons or tabs to use.

Got to thinking more, my old version of this mod has it's own built in content selection mechanism. Thought some more and have a strong suspicion that various custom themes may work better with core or better with default. Some may work with neither.

So my tentative solution is to have the mod default to selecting automatically between default and core. If it can't figure it out which it can use my old built-in method, and lastly I decided it might be fun to use a drop down list to select all the various modes:

1. Automatic - picks default or core if it can be determined which, or uses compatibility mode otherwise.
2. Default - forces default for forums that don't have default theme installed but their theme works with the default template selection method.
3. Core - same as above but forces core method.
4. Compatibility - uses neither default nor core but instead activates the mod's built in content selector.

Tentatively I think I'll do it this way. Then I need only one template file, and possibly this might make it easier for ppl using custom themes to use the mod.

What do you think? I've never used custom themes. Do themers rewrite all the template files or what? Is my solution over-design?

The alternative is to just have it select automatically, default to compatibility mode if it can't determine if core or default are being used, and have a check-box to force compatibility mode in case some themer wants that.

Which is the best approach?

Arantor

Basically you can't. This is why you try and avoid theme edits wherever possible. Most things can actually be done with more or less difficulty without theme edits.

If you must do theme edits, ignore the Core theme, address $themedir and anyone using Core - or other custom themes - will just have to deal with it. Most themers, though, don't touch the templates other than the index template because of mod compatibility issues (which some themers have vehemently argued is why most SMF 2.0 themes are bland and insipid because they're less capable of being creative, which is largely untrue but it doesn't stop the argument being made)

Just think: in a mod of SimpleDesk's complexity and size, there are only a few template edits, and those are for things that cannot be done meaningfully any other way. Hell, it is quite happy to modify the board index icons on things, plus remove the quick search box under the right circumstances - all without touching the theme, so it is entirely possible. (For reference: the theme edits it makes are to the manage-attachments code, since it extends the SMF attachments system for itself, the package manager when it declares a new kind of package, and the view-IP area when it displays messages posted with that IP address)
Holder of controversial views, all of which my own.


Deprecated

I've been looking at the SMF settings with the word "theme" in them, and have found it's not that easy. It looks like you might be able to decide which theme the user is running based upon various database settings but some of them are (0, 1, 2, 3) and I see no guarantee those correspond to any specific named themes. It's too bad there isn't a $context['current_theme'] variable = 'default', 'core', 'some custom name', etc. I'm looking at some other arrays, particularly, is it $user[]? I forgot, I just got back to "work" after "dinner."

Arantor

Except none of that is exposed to the package manager anyway so it's totally irrelevant.
Holder of controversial views, all of which my own.


Deprecated

Quote from: Sir Cumber-Patcher on January 30, 2014, 07:04:05 PM
Basically you can't. This is why you try and avoid theme edits wherever possible. Most things can actually be done with more or less difficulty without theme edits.

I have two versions of my template, one works with core's tabs, one which deals with curve's buttons, but the class names differ. I have two versions of my template, one with each set of class names and how to deal with the template differences.

I've gone to too much effort to move this mod to the integration hooks only to be stuck on a much less important difference. It's too bad that curve and core don't use the same class names and then just load different CSS files.

Very frustrating. I feel I'm so close yet I can't find which method to automatically select. I could provide a choice in my mod package, 1 curve, 2 core, 3 compatibility, but that would be really Mickey Mouse to have my mod not automatically switch between themes. And what of the users, would every one of them have to configure my mod too look good in their view of the forum?

Deprecated

Quote from: Sir Cumber-Patcher on January 30, 2014, 08:15:05 PM
Except none of that is exposed to the package manager anyway so it's totally irrelevant.

I'm discussing deciding in real time, not when the mod is installed, although the topic has drifted. What I want to do is install one template in default and then have the template decide whether it's being used in default or otherwise, and make the decision in real time what code to execute. I have three choices: code that is compatible with core, code that is compatible with curve, code that is comparable with both but is ugly.

If I can decide in real time which theme is being executed, core, curve or other, then I can handle with just the one template which HTML to deliver.

Arantor

Which is also futile because there are themes out there based on Core (as themes can actually do that, outright specify a theme to be based on, which can but does not have to directly use the name) - the reality is that you just cannot do it. Since the (vast) majority of users are using Curve or Curve based themes, you are far better just worrying about that and dealing with Core if it comes up. Though frankly if you're doing any more than just changing a parameter to template_button_strip you're probably doing it wrong anyhow.
Holder of controversial views, all of which my own.


Deprecated

Probably so. I'll just issue two templates since I think any other way of dealing with it requires me to know far more about SMF internals and it's means of dealing with themes than I know now.

I can add a check button "multi-theme compatible mode" that imports content selection to within my mod's template.

Arantor

*shrug* You're making so much more work for yourself than to just stop worrying about it. Mind you, you've made it clear that you intend to make more work for yourself than you really need (mods do not need to continue supporting beta and RC versions for example and we'd prefer people to encourage, not discourage, upgrading anyway)

Best of luck to you (resumes ignoring)
Holder of controversial views, all of which my own.


Deprecated

I haven't found any way to deliver the buttons used in curve and the tabs used in core with the same code. The classes used are different.

Core uses div id "admin_container," ul class "admin_menu," wants first and last tabs to be identified in the class name (so it can curve the tab background) and selected tab identified by adding "chosen" to the class.

Curve uses div id "admin_menu"," ul class "dropmenu" and adds the word "active" to the link (a) class to indicate selected button.

At least that's how I reverse engineered it. Perhaps there's a better way to do it but reverse engineering results in a way to do it, not the best way to do it. If you can point me to instructions on how to use a method that is both core and curve compatible I will appreciate it.

Your conclusion that I want to make more work for myself is erroneous in that I may be making more work for myself but it's not wanted. But I do want to achieve compatibility with both of the basic themes that come with the standard SMF installation.

Or perhaps I've misunderstood you. Did you mean that it's not worth making my mod look pretty with both themes?

All Colours Sam

Without looking at the code it would be utterly difficult to say if there is a better approach, looks to me that you want to build a spaceship and an international space station just to help you cross a river when its quite possible that if you walk a few steps you will find a bridge.

About core, no one cares about core, not even SMF's code itself, not even the customization guidelines. It was the default theme, sure, but now its just another theme, it was left there for legacy purposes, nothing more. If you found a person using core, you provide support for said person when and only if that ever happens.
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

Deprecated

Is there an integration hook that adds either core's tabs or curve's buttons, accepting the same button array? Like the "Home," Help," "Search," "Profile," ... above?

If you have an option then somebody is bound to use it. Since nobody uses core why not just delete it from future releases? Maybe your legacy looks to me like "a spaceship and an international space station." Why not just dump it and then everybody can just walk across the bridge?

I don't like writing code that looks crappy with some user and/or forum choices.

Arantor

Well... all the menu buttons are in Subs.php like they have been for several years now, and both themes pull from that... and there's a hook there too called integrate_menu_buttons for that reason.

2.1 only has its own theme and the Wireless template (not that that's technically a theme anyway), and that was done years ago for the exact reason you mention.
Holder of controversial views, all of which my own.


Deprecated

Like integrate_menu_buttons but for use in creating a second level menu below the main buttons but before the main content, like above "Reply," "Add Poll, "Notify," ... Under the bread crumbs, over the content.

I'm already using integrate_menu_buttons but it won't work because I'm making a sub-menu, not adding to the main menu. (I added one button to the main menu.)

Arantor

You can add sub-menus to the items in the main menu - like the admin menu is for example...

If you really need to create a true separate navigation menu like you're talking about, template_button_strip is the thing to use. As ever, please refer to SimpleDesk where you will see this in action.
Holder of controversial views, all of which my own.


Deprecated

Thanks!!! That's what I was looking for. I just didn't know where to look. I'll do it right now! :)

Arantor

And my telling you to use template_button_strip previously wasn't a big enough hint?
Holder of controversial views, all of which my own.


Advertisement: