How to use actions and filters to replace content?
-
Hello,
I checked the docs and there are two examples: how to include custom content and how to prevent the template from being generated.
But how do I replace one with another?
When filter is used, the hooks are gone and I cannot attach my custom content to it anymore:add_action( 'tribe_template_before_include:events/v2/list/event/description', function ( $file, $name, $template ) { $event = tribe_get_event( get_the_ID() ); echo ( get_field('certified') ) ? 'Yes' : 'No'; echo esc_url( $event->permalink ); }, 10, 3 ); add_filter( 'tribe_template_pre_html:events/v2/list/event/description', '__return_false' );
-
Hi @zerocore, thanks for reaching out to us. That’s a good question. I reached out to one of our devs, and here’s what he suggested:
Instead of using
tribe_template_before_include
as in your example, you should drop the
tribe_template_pre_html // don't do this!
and instead of removing it, override it with
tribe_template_include_html
Let me know how it goes on your end.
Best,
AbzThanks.
I did it like this:
add_action( 'tribe_template_include_html:events/v2/list/event/description', function ( $html, $file, $name, $template ) { $template->template( 'event-summary' ); }, 10, 4 );
But for some reason I cannot do the same for
latest-past
:add_action( 'tribe_template_include_html:events/v2/latest-past/event/description', function ( $html, $file, $name, $template ) { $template->template( 'event-summary' ); // does nothing }, 10, 4 );
Hi @zerocore, thanks for getting back to us. Good to know that the override works for the list. Appreciate you confirming this. Regarding the latest past events, I’d reach back to our devs and check with them what’s missing here or if there is a workaround.
I’d get back to you whenever I hear from the team. Have a great day.
Best,
AbzHello @zerocore, quick question is event-summary your custom template? We’re trying to figure it out as well.
Looking forward to your response.
Best,
AbzYes and it’s path is
my-theme/tribe/events/v2/event-summary.php
, but for some reason I cannot access it on thelatest-past
template.Hi @zerocore, one of our dev confirmed that it works. I also tested it out. Could you re-try and apply this snippet here:
add_action( 'tribe_template_include_html:events/v2/latest-past/event/description', function ( $html, $file, $name, $template ) { $template->template( 'event-summary' ); }, 10, 4 );
See screenshots here:
https://share.getcloudapp.com/DOudmjr7
https://share.getcloudapp.com/X6uR8Y5qLet me know how it goes on your end.
Best,
AbzI tried on two different websites and i cannot make it work.
It will print echo message, but not the content from the template.
And if the file is missing, I get error in thelist
, but nothing in thelatest-past
:We looked for a template file for the list slug but could not find one. This was rendered by the Tribe\Events\Views\V2\Views\List_View View. We've looked in the following locations: Id: plugin Priority: 20 Path: /plugins/the-events-calendar/src/views/v2 Id: common Priority: 100 Path: /plugins/the-events-calendar/common/src/views/v2 Template context: { "slug": "list" }
Not sure if it helps, but I tried to
print_r($template);
and here how it looks onlist
:[template_file_cache:protected] => Array ( [list] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list.php [components/loader] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/loader.php [components/icons/dot] => my-theme-path/wp-content/plugins/the-events-calendar/common/src/views/v2/components/icons/dot.php [components/json-ld-data] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/json-ld-data.php [components/data] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/data.php [components/before] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/before.php [components/messages] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/messages.php [components/breadcrumbs] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/breadcrumbs.php [components/events-bar] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/events-bar.php [components/events-bar/search-button] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/events-bar/search-button.php [components/icons/search] => my-theme-path/wp-content/plugins/the-events-calendar/common/src/views/v2/components/icons/search.php [components/events-bar/search] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/events-bar/search.php [components/events-bar/search/keyword] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/events-bar/search/keyword.php [components/events-bar/search/submit] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/events-bar/search/submit.php [components/events-bar/views] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/events-bar/views.php [components/icons/list] => my-theme-path/wp-content/plugins/the-events-calendar/common/src/views/v2/components/icons/list.php [components/icons/caret-down] => my-theme-path/wp-content/plugins/the-events-calendar/common/src/views/v2/components/icons/caret-down.php [components/events-bar/views/list] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/events-bar/views/list.php [components/events-bar/views/list/item] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/events-bar/views/list/item.php [list/top-bar] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/top-bar.php [list/top-bar/nav] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/top-bar/nav.php [list/top-bar/nav/prev-disabled] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/top-bar/nav/prev-disabled.php [components/icons/caret-left] => my-theme-path/wp-content/plugins/the-events-calendar/common/src/views/v2/components/icons/caret-left.php [list/top-bar/nav/next] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/top-bar/nav/next.php [components/icons/caret-right] => my-theme-path/wp-content/plugins/the-events-calendar/common/src/views/v2/components/icons/caret-right.php [components/top-bar/today] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/top-bar/today.php [list/top-bar/datepicker] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/top-bar/datepicker.php [components/top-bar/actions] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/top-bar/actions.php [components/top-bar/actions/content] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/top-bar/actions/content.php [components/filter-bar] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/components/filter-bar.php [list/month-separator] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/month-separator.php [list/event] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/event.php [list/event/date-tag] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/event/date-tag.php [list/event/featured-image] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/event/featured-image.php [list/event/date] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/event/date.php [list/event/date/featured] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/event/date/featured.php [list/event/date/meta] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/event/date/meta.php [list/event/title] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/event/title.php [list/event/venue] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/event/venue.php [list/event/description] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/list/event/description.php [event-summary] => my-theme-path/wp-content/themes/theme/tribe/events/v2/event-summary.php )
And here’s
latest-past
:[template_file_cache:protected] => Array ( [latest-past] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past.php [latest-past/heading] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/heading.php [latest-past/event] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/event.php [latest-past/event/date-tag] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/event/date-tag.php [latest-past/event/featured-image] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/event/featured-image.php [latest-past/event/date] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/event/date.php [latest-past/event/date/featured] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/event/date/featured.php [latest-past/event/date/meta] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/event/date/meta.php [latest-past/event/title] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/event/title.php [latest-past/event/venue] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/event/venue.php [latest-past/event/description] => my-theme-path/wp-content/plugins/the-events-calendar/src/views/v2/latest-past/event/description.php )
Hi @zerocore,
Thanks for providing more information here. I’d share this with the team and I’d get back to you whenever I know more. Please note that this is free support and might take a while.
Have a great day.
Best,
AbzHello @zerocore, one of our devs got back to me and recommended doing a Template Override, as this could be more customizable rather than using hook/function.
See the article here to learn more:
https://theeventscalendar.com/knowledgebase/k/customizing-template-files-2/For the latest-past description, override this template:
the-events-calendar/src/views/v2/latest-past/event/description.php
by creating this template on your child theme:
[your-child-theme]/tribe/events/v2/latest-past/event/description.php
And for the list view, override this template:
the-events-calendar/src/views/v2/list/event/description.php
and create this template on your child theme:
[your-child-theme]/tribe/events/v2/list/event/description.php
You would be able to add custom content to these templates.
Let us know how it goes on your end.
Best,
AbzHello,
that’s exactly what I did.
I just wanted to try utilize my themes capabilities and attach block content via hooks, but looks like The Events Calendar is not ready for that ??
Hi @zerocore, thanks for confirming here. Perhaps it is a limitation on our plugin. Sorry to hear about this.
Regarding this customization/feature — I encourage and recommend you to add it as a feature request at this link: https://evnt.is/ideas. This would help us track users needing this feature.
Nevertheless, I am unable to provide you with an exact date for when this feature will be available or if it is possible. Our development team considers certain factors before implementing one, like if a feature request has enough votes.
Appreciate your time and for bringing this to our attention. Please do not hesitate to bump a new ticket on our way. We’d be glad to help you out.
Have a great day.
Best,
AbzHi @zerocore,
We haven’t heard from you in a while, so I’m going to mark this as resolved. Feel free to start a new thread if you have any more questions.
Best,
Abz
- The topic ‘How to use actions and filters to replace content?’ is closed to new replies.