Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only evaluate the first template definition #282

Merged
merged 10 commits into from
Mar 3, 2023

Conversation

ternite
Copy link
Contributor

@ternite ternite commented Jan 31, 2023

Uses the usecounter plugin to be able to restrict multiple template definitions to the first one, instead of the last one.

Comes with a boolean configuration option firsttemplatedefinitionwins. If set to true, only the first template command will be evaluated. If set to false, the original behavior will be enacted, i.e. all commands are executing, which results in the last command actually setting the template.

resolves #281

Pages nested with the include plugin may contain several odt:template definitions. The option 'firsttemplatedefinitionwins' allows to have the first definition win the contest (true), or the last one (false).
...so it will keep the value consistent throughout one walkthrough, but be reset every time a new walksthrough is started
@Klap-in
Copy link
Collaborator

Klap-in commented Feb 24, 2023

For the settings via syntax I did saw two other templates odt_template or css_template settings, but not yet template. Are these also supported?

{{odt>setting:value}}

https://www.dokuwiki.org/plugin:odt#configuration

Further, it seems you are using tabs. Could you please change these in spaces?

I understand this change as not completely backward compatible. So in the changelog we need to pay attention to it.

@ternite
Copy link
Contributor Author

ternite commented Feb 25, 2023

@Klap-in Thanks for your comment! I wasn't aware of the other configuration options. Looks like I implemented my wiki when those were not existing, yet.
I made an update to the branch with the following properties:

  • The syntax tags css_template, odt_template, and templatepage will be counted as a usage of template, too.
  • Added more commenting and documentation - the most important detail is mentioning in the plugin configuration text for firsttemplatedefinitionwins that this option needs the usecounter plugin to work.
  • Changed default value to 0, so plugin behavior will be the same as in previous versions of the plugin, even if the usecounter plugin is installed and activated. (Does this resolve your considerations towards backward compatibility?)
  • Changed the occurrences of tab characters to spaces.

Here are the additions that could be made to the dokuwiki page of the odt plugin:

In section "Configuration" - addition of:

| firsttemplatedefinitionwins      | In case of multiple definitions of template, templatepage, css_template, or odt_template, the first will be used. (The value false will apply the last definition, instead.) **Needs the usecounter plugin!**                                                                                              |

In section "Templates support" - addition of a new paragraph right before the next section "PDF conversion":

=== Use the first or last template defition? ===

In a setting with nested pages, e.g. when using the [[plugin:include|include plugin]], the classic behavior of this plugin was to use the very last template definition, when multiples were made. This may be undesired, so there is a configuration setting ''firsttemplatedefinitionwins'' which changes this behavior to evaluating only the very first template definition. This configuration parameter needs the [[plugin:usecounter]] plugin to work! Also, the default value of this config option is ''0'' (''false''), so it does not change the plugin behavior if you upgraded from an earlier version of this plugin.

Best regards
Thomas

@Klap-in
Copy link
Collaborator

Klap-in commented Feb 25, 2023

Thanks for improving.
I did not realise the dependency of the usecounter plugin, even while you mentioned it already. My feeling is that implementing a counter directly in odt can be quite straight forward, this extra plugin does it nice, but for me it still feels as extra burden for the user to install an extra plugin only for just this setting and it is an extra possibility for confusion. Would it not simplify the usage of the setting to implement the counter directly in odt plugin?

With the new default setting the situation is indeed backward compatible.

Nice that you propose already the documentation updates.

@ternite
Copy link
Contributor Author

ternite commented Feb 25, 2023

I implemented it this way because I am using another private plugin which needs the same functionality. Also, since you have to actively opt-in the new behavior, you will have to manually set the configuration value and you're reminded therein of this dependency. I don't feel it's much of a burden to install another small plugin if you want/need this functionality.

Also, there is way more code in that plugin than in this branch, here. You need an action handler, and a helper class. To integrate that code into plugin:odt seemed complicating the matter a lot in relativity to the few lines added within this branch. I did not want to blow up the odt plugin even more than it already is, just because of some niche functionality (I seem to be the first person to perceive the resolved problem).

helper/config.php Outdated Show resolved Hide resolved
@ternite
Copy link
Contributor Author

ternite commented Mar 3, 2023

@Klap-in hi, you merged master into this branch - will you be going to merge the branch into master, too?

helper/config.php Outdated Show resolved Hide resolved
@Klap-in Klap-in merged commit aac166c into lpaulsen93:master Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overwritten template definition in nested pages
2 participants