-
Notifications
You must be signed in to change notification settings - Fork 27
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
base: master
Are you sure you want to change the base?
Conversation
- 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] ) ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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. |
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 |
I could see it working like this:
|
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. |
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.