I have a plugin that uses its own templates, in this case single-ajde_events.php. I have copied this .php file and it loads sucessfully from my themename/resources folder.
However, I fail to manage to integrate this template into the blade template structure. I have consulted the eBook, searched the forums, Google, but I only found a couple of topics trying to accomplish this with WooCommerce and Sage9, so I tried the solution presented there:
I added <?php echo App\Template('single-events'); ?> to the template file and created a single-events.blade.php file in the same folder.
What happens is that this seems breaks something. The page does not load anymore and even the loading time of all other pages is increased tremendeously. When I remove the above code and rerun Yarn, everything returns to normal.
What is the proper way in Sage 9 to accomplish this? Basically, I want these template files to redirect to my own blade-templates so I can keep working within the same structure.
Hey @manalyse - if the plugin is using a custom post type and its template is named single-ajde_events.php, then thereâs a good chance itâs compatible with the normal WordPress template hierarchy. If thatâs the case, you can try just using single-ajde_events.blade.php instead of single-ajde_events.php. At that point you can put whatever Blade code in the template you want.
Hey @mmirus, thanks for your help. Unfortunately, that did not work. It does not find the blade-file. I checked if the plugin uses custom post types, and it does use the custom post type ajde_events.
Yes. I tried that. I have put the file in every folder in the theme, including eventon folders in every subdirectory (theme root, resources, views, partials) to check if thatâs the issue - itâs not.
I took a look at the plugin code and this should work for you. Put your single-ajde_events.blade.php file in views, and add this code to app/filters.php:
The problem remains, however, that none of the functions that I find in the original template file, such as do_action('eventon_single_content') seems to work in the blade file.
I tried to do this in controller/app.php:
public function eventonSingle() {
$eventonSingle = do_action('eventon_single_content');
return $eventonSingle;
}
But that does not seem to help either. Am I misunderstanding/overlooking something obvious thatâs sage-related, or is it a plugin-related issue?
I have tried two different versions now to test it.
When I try the following in the single-ajde_events.blade.php
<section @php(post_class())>
<h1>This is the single-ajde_events.blade.php file.</h1>
<?php do_action('eventon_single_content'); ?>
</section>
It just returns the content of the <h1> tag (I know I can use the @php directive but I wanted to rule out any potential errors related to that).
When I try
<section @php(post_class())>
<h1>This is the single-ajde_events.blade.php file.</h1>
{!! $eventonSingle !!}
</section>
I get the error message Undefined variable: eventonSingle in /srv/www/manalyse.de/current/web/app/uploads/cache/07699fdd0b9590b28a3cb1439ecd75d7d1bbb740.php on line 3
Itâs also blank (except for the <h1>) when I try
@extends('layouts.app')
@section('content')
@while(have_posts()) @php(the_post())
<h1>This is the content-single-ajde_eventsblade.php file.</h1>
<?php do_action('eventon_single_content'); ?>
@endwhile
@endsection
Thanks for the info! Using the @php(do_action('action_name')) syntax is the approach you want (see app.blade.php, for example).
Canât say for sure since I only have an older version of the plugin for testing, but I donât think anything is actually supposed to be displayed from those actions out of the box. Instead, you (or addons) could use those actions to do your own thing at those points in the template.
Take a look at the pluginâs template file (single-ajde_events.php) and see whatâs in there. In my version, they output the actual content by including content-single-event.php. Thatâs where it constructs the HTML thatâs printed. You would need to include that in your Blade template or write your own template code to output the events details using that partial from the plugin as a starting point (this is probably the point where you would use a controller to prepare the event data for your Blade template).
In case itâs helpful, Iâve included an example of how you might modify app.blade.php and a sample single template to add most of the actions they talk about in their docs. (I didnât include the sidebar action.)
app.blade.php - adds eventon_before_main_content and eventon_after_main_content:
Thanks, I have added these codes, but they donât seem to allow me to call the necessary functions to actually get any of the data. I mean, I am using the same technique to get ACF data to my templates, but it does not seem to work with eventON.
I donât understand at all why these functions donât work. I am looking at the content-single-event.php just like you suggest, and this is the code:
If I copy any of this into my template, nothing gets displayed. Also tried adding these functions via controller app (like I do with ACF as is described in the eBook). Nothing.
Oh, yeah, theyâve really cleaned that up since the version I have and looks like they probably moved a lot to the actions that was handled directly in the template in the older version.
Since my version is different I canât directly help too much beyond this point.
But one thing you might try is open up the entire plugin folder in your editor and search for those actions (e.g., search the entire plugin codebase for eventon_oneevent_event_data).
What you want to find is where they have something like add_action('eventon_oneevent_event_data', ...). That will help you track down what happens in the plugin when that action fires. If you find that, you can see what code they are using and might be able to find out why it isnât working. You may not be able to directly fix it, but you might be able to see what you could add in your controller / template to recreate what theyâre doing in a way that works.
You may also be able to contact the plugin author for support to see if he has any advice - not sure how far heâd be willing to go to support overriding the templates in a theme like Sage, but he might be able to give you some pointers, at least.
Well, thanks a lot for your help, although it did not solve the problem in the end, it was much appreciated and I have learned a lot!
I think I will have to look for a different solution for this altogether. It is too much work going into the code this deep just to be able to have more stylistic control. Although using the default template creates many other problems.