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

Add functionality for widget instances to have unique templates #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tbartels
Copy link

I needed a way to use unique templates for each Taxonomy Drill-Down widget. Inspired by WordPress' get_template_part I added the ability to do something similar in the widget instance config. It is now possible to add a 'suffix' parameter to each widget which will make the template renderer look for the functional equivalent of "qmt-templates/{$mode}-{$suffix}.html" before the default template.

- create a simple way to have widget instance specific template files based on a configured suffix, similar in concept and execution to WP `get_template_part`
- add `scbWidget::input` text element for template suffix configuration
- add template tag `{{{suffix-input}}}` to widget instance form template
- adjust `Taxonomy_Drill_Down_Widget::mustache_render` to use a hierarchical array of temlate search paths with `locate_template`"
realized I was over-thinking some things and cleaned things up to hopefully be more readable and understandable
if ( is_array( $data ) && !empty( $data['suffix'] ) ) {
// split the base template into its components and throw away the
// dirname if it is '/' or '.'
extract( pathinfo( $templates[0] ) );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think replacing all that with a call to sanitize_title_with_dashes( $data['suffix'] ) would be both cleaner and more secure.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or rather, call sanitize_title_with_dashes(), and construct the $templates array later, instead of constructing and then destructuring it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, and probably even better would be to use sanitize_file_name, I'll adjust and commit.

- procedurally add template names instead of trying to manipulate an array
- use WP `sanitize_file_name` to clean the user input suffix
@scribu
Copy link
Owner

scribu commented Jan 23, 2013

I figured out what I don't like about the patch: Instead of making the user write out an arbitrary suffix, we should show a dropdown, with the list of available templates in the theme.

@tbartels
Copy link
Author

That was my original approach but it added the complexity of verifying the different modes against the templates. If I display a list of all templates the end-user could select list-suffix.html while having chosen the dropdown mode, should this error on the widget form, or just let the user figure it out via documentation? Should it list all templates regardless of name, or only those prefixed with dropdowns, lists, checkboxes?

@scribu
Copy link
Owner

scribu commented Jan 23, 2013

I could see it working like this:

  1. Generate 3 dropdowns, one for each mode.
  2. Switch which one is displayed based on what mode is currently chosen.

@tbartels
Copy link
Author

That's where I started, but found it to be a whole lot more UI than necessary. I'll see if I can find the time to re-implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants