masugadesign / lab-reports-craft-cms

Other
2 stars 1 forks source link

Error when try to include a template in the reports. #4

Closed amici-infotech closed 1 year ago

amici-infotech commented 1 year ago

I get this error when I try to use macros in the report templates. It looks like this:

image

It says template not found but macros is there. After debug the code, i found this a culprit.

In services/Reports.php if I change line 69 from:

$view->setTemplatesPath(Craft::$app->getPath()->getSiteTemplatesPath());

to

$view->setTemplateMode(\craft\web\View::TEMPLATE_MODE_SITE);

then it all works great.

benjaminkohl commented 1 year ago

If I am not mistaken, removing the originaly line was not necessary for adding the other line. It may even cause problems for reports that are executed via the queue. Maybe both lines should be included.

benjaminkohl commented 1 year ago

I was unable to reproduce this error with version 2.0.1 and Craft 4.4.5 using a macro in the template. Can you provide more details about your installation and how you are generating reports?

It looks like you have a template folder that is simply called "_". I wonder if that could be a factor.

amici-infotech commented 1 year ago

I am on Craft v4.4.7.1 with Plugin v2.0.1.

here is my code.

{#
Report Title : All Subscribers
Report Description : List of all subscribers.
Report Template : _/reports/all-subscribers
#}

{% include "_/reports/new-subscribers/index" with {
    gap: null,
    report: report
} %}

Where _ is my folder name where I store all the layouts, reports, includes etc. I need to use include because i need the same repeating code for new subscribers in last week, last month, in 6 month, all time subscribers

amici-infotech commented 1 year ago

If I am not mistaken, removing the originaly line was not necessary for adding the other line. It may even cause problems for reports that are executed via the queue. Maybe both lines should be included.

If we change it to set TEMPLATE_MODE_SITE, we wont really need to store the path. PATH of frontend template will be manage by craft itself.