Qoraiche / laravel-mail-editor

MailEclipse :zap: Laravel Mail Editor
Other
2.09k stars 259 forks source link

Template preview not working? #210

Closed jornwildenbeest closed 5 months ago

jornwildenbeest commented 2 years ago

Describe the bug

Maybe I am missing someting, but I think the template preview is not working when you go and use the preview mode when editing a template directly (not going through a mailable). When I click the preview button it just shows a white black page in the text editor.

url: https://laravel.test/maileclipse/templates/edit/yourtemplate.

stacktrace:

[2022-06-21 11:27:37] local.ERROR: Method Qoraiche\MailEclipse\Http\Controllers\TemplatesController::previewTemplateMarkdownView does not exist. {"userId":2,"exception":"[object] (BadMethodCallException(code: 0): Method Qoraiche\\MailEclipse\\Http\\Controllers\\TemplatesController::previewTemplateMarkdownView does not exist. at /Users/jorn/Sites/**/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:68)
[stacktrace]
#0 /Users/jorn/Sites/**/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Illuminate\\Routing\\Controller->__call('previewTemplate...', Array)
#1 /Users/jorn/Sites/**/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('previewTemplate...', Array)
#2 /Users/jorn/Sites/**/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(Qoraiche\\MailEclipse\\Http\\Controllers\\TemplatesController), 'previewTemplate...')
#3 /Users/jorn/Sites/**/vendor/laravel/framework/src/Illuminate/Routing/Route.php(204): Illuminate\\Routing\\Route->runController()
#4 /Users/jorn/Sites/**/vendor/laravel/framework/src/Illuminate/Routing/Router.php(725): Illuminate\\Routing\\Route->run()
#5 /Users/jorn/Sites/**/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))

Reproduction steps

Steps to reproduce the behavior:

  1. Go to Templates
  2. Add template
  3. Save template
  4. Click preview template

Laravel Version:

v9.17.0

MailEclipse package version:

v4.0.3

Screenshots (if applicable)

afbeelding

ReeceM commented 2 years ago

Hi @jornwildenbeest thank you for opening the issue.

I will have a look at this and revert back 👍

jornwildenbeest commented 2 years ago

Hi @ReeceM, Another question about the templates.

Is it possible to link multiple templates to one mailable?

I have a situation where I use one mailable with different templates (but all same variables from the mailable). But i'd like to see the mailable variables when editing the templates. Right now this is only possible when editing the mailable and not the templates it self.

ReeceM commented 2 years ago

It looks like the error is from a deprecation of some internal method calls, but I think this was not on purpose. I'll have to look a little more as to what changed or why. Thank you for noticing it :100:

With regards the second question, I don't think the package was originally designed with that in mind. Although that does sound like a good addition to the package. May need to think how that would get interpreted by the package if there is an a 'go ahead' for it from Yassine.

ReeceM commented 2 years ago

Hey @jornwildenbeest,

Please could you try this fix before I tag it as a release :+1:

 composer require qoraiche/laravel-mail-editor:dev-fix/route-errors
jornwildenbeest commented 2 years ago

Hi @ReeceM, thanks for the reply. I will try it later today and let you know!

ReeceM commented 2 years ago

Thank you, feedback would be great

jornwildenbeest commented 2 years ago

@ReeceM I can confirm it is working! Which is great.

Except when you are using variables within the template. It then shows a notices that you can't use variables in the template preview mode, which is fine, I can understand why but it would be a great feature to use the factory to load the variables like you do with the maillables.

But we do need the connection between template and mailable to get that to work i guess.

ReeceM commented 2 years ago

@jornwildenbeest I'm glad it is working then. Unfortunately there was a bit of regression and the new implementation was lost I think 🤦‍♂️

So loading the variables you are right with needing the mailable class to be able to link those properly.

But we do have a way to generate those details. I must just see if the reflection loader still works. It's the other part of the system that generates the fake variables when a type isn't defined in the mailable.

There could probably be basic support for simple variables, just not sure of any that would need to be looped over, can't always tell what a person is needing in that instance :)

jornwildenbeest commented 2 years ago

@ReeceM Another idea might be to have the option to select a template when you are in the preview mode in mailable.

When you visit a mailable, the preview mode shows the template that is loaded through the build function in the mail class.

Maybe its a nice feature to have an select input field with all templates, and you can select which template you want to preview.