wintercms / wn-blog-plugin

Blog plugin for Winter CMS
https://wintercms.com/
MIT License
17 stars 21 forks source link

After Update - An exception has been thrown during the rendering of a template #38

Closed 01Kuzma closed 1 year ago

01Kuzma commented 1 year ago

Winter CMS Build

dev-develop

PHP Version

8.1

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

Just updated the working Winter CMS 1.2.1 with composer update and winter:up commands, and it's broken now. The last update I did was about two months ago.

Steps to replicate

So, I get the An exception has been thrown during the rendering of a template ("Undefined array key "about"") in "C:\laragon\www\winter3\themes\mytheme\partials\intro.htm" at line 3.

intro.htm points to hero1.htm which post list component:

[viewBag]

[blogPosts]
pageNumber = "{{ :page }}"
postsPerPage = 7
noPostsMessage = "No posts found"
sortOrder = "random"
categoryPage = "about"
postPage = "blog-post"
==

As I understand the error is pointing to categoryPage = "about" part. Before the update, it was working

Workaround

No response

mjauvin commented 1 year ago

Try artisan cache:clear maybe ?

mjauvin commented 1 year ago

Otherwise, please post your intro.htm file here

01Kuzma commented 1 year ago

Yes, I've already cleared the cache.

the intro.htm, there is nothing special:

[viewBag]
==
<!-- Hero Slider parts -->
<div class="hero-section">
    {% partial 'hero-slider/hero1' %}
    {% partial 'hero-slider/hero2' %}
    {% partial 'hero-slider/hero3' %}

    {% if this.theme.intro_social_menu %}
    <div class="hero-social-links">
        <a href=""><span style="font-size: 1em;"><svg class="svg-icon"><use xlink:href="#icon-facebook"></use></svg></span></a>
        <a href=""><span style="font-size: 1em;"><svg class="svg-icon"><use xlink:href="#icon-youtube"></use></svg></span></a>
        <a href=""><span style="font-size: 1em;"><svg class="svg-icon"><use xlink:href="#icon-instagram"></use></svg></span></a>
    </div>
    {% endif %}
</div>
<!-- Intro section   -->
{% if this.theme.intro_homepage_section %}
<section class="intro-section">
    <div class="intro-warp">
        <div class="container-fluid">
            <div class="row">
                <div class="col-xl-6 col-lg-7 p-0">
                    <div class="intro-text">
                        <h2>{{ this.theme.intro_headline | raw }}</h2>
                        <p>{{ this.theme.intro_text }}</p>
                        <a href="portfolio" class="sp-link">{{ this.theme.intro_portfolio }}</a>
                    </div>
                </div>
                <div class="col-xl-6 col-lg-5 p-0">
                    <div class="skill-warp">

                        <img src="{{ 'assets/img/intro.jpg'|theme }}" class="" alt="" />

                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
{% endif %}
<!-- Intro section end  -->

and hero1.html

[viewBag]

[blogPosts]
pageNumber = "{{ :page }}"
postsPerPage = 7
noPostsMessage = "No posts found"
sortOrder = "random"
categoryPage = "about"
postPage = "blog-post"
==
<!-- Hero section-1 -->
<div class="hero-slider owl-carousel">
    {% for post in posts %}
    <div>
        {% for image in post.featured_images|slice(0,1) %}
        <!-- get 1 image from featured-images -->
        <div class="hero-item portfolio-item set-bg lazyload" data-setbg="{{ image.path | resize(600,600) }}">
            <a href="{{ post.url }}" class="hero-link">
                <h4>{{ post.title }}</h4>
            </a>
        </div>
        {% endfor %}

    </div>
    {% endfor %}
</div>
mjauvin commented 1 year ago

post your theme.yaml file

01Kuzma commented 1 year ago

here it is:

name: Foto
description: 'Multipurpose Theme for Portfolio, Corporate, Gallery, Agency, Blogging, Resume, etc. Basically, this is designed for Photografer, Bussiness, Creative Professional, Painting/Image Gallery & Product Showcase.'
author: 01Kuzma
homepage: www.kuzma.lt
code: ''
form: fields.yaml
require:
    - rainlab.blog
    - LaminSanneh.FlexiContact

I suppose, that I've to change the rainlab.blog to winter.blog

P.S. just changed the ti winter.blog, the same

LukeTowers commented 1 year ago

None of your files should be ending in .html, it should be .htm. Please also post the contents of the about.htm page.

01Kuzma commented 1 year ago

Sorry, it was indeed .htm, I've just made a typo. Here is a little bit contracted about.htm, just removed some HTML elements:

title = "Apie"
url = "/apie"
layout = "default"
meta_title = "Apie"
meta_description = "Some meta INFO"
is_hidden = 0
robot_index = "index"
robot_follow = "follow"
==
<section class="about-section">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-6 p-0">
                <div class="about-bg set-bg" data-setbg="{{ image.path }}">
                    {% if this.theme.about_photo %}
                    <img src="{{ this.theme.about_photo.getThumb(950, 835, 'crop') }}" class="img-fluid" alt="" />
                    {% else %}
                    <img src="{{ 'assets/img/about.jpg'|theme }}" class="img-fluid" alt="" />
                    {% endif %}
                </div>
            </div>
            <div class="col-lg-6 p-0">
                <div class="about-text">
                    <h2>{{ this.theme.about_us_headline | raw }}</h2>
                    <p>{{ this.theme.about_us_text | raw}}</p>
                    <h4>{{ this.theme.about_clients_headline | raw }}</h4>
                    <p>{{ this.theme.about_clients_text }}</p>
                    <h4>{{ this.theme.about_editorials_headline | raw }}</h4>
                    <p>{{ this.theme.about_editorials_text }}</p>
                    {# <a href="{{ this.theme.about_button_link|page }}" #}
                    <a href="{{ this.theme.about_button_link }}"                    
                        class="site-btn">{{ this.theme.about_contact_button }}</a>
                </div>
            </div>
        </div>
    </div>
</section>

<div class="skill-section set-bg" data-setbg="{{ 'assets/img/horizontal-divider.jpg'|theme }}">
    <div class="container-fluid">
        <div class="row">
            <div class="col">                
                <div class="text-center">                  
                  <h1 class="text-white"><h1>
                </div>                
            </div>
        </div>
    </div>
</div>

{% if this.theme.services_about_page %}
<section class="services-section">
    <div class="container-fluid">
        <div class="row">
            <!--HTML-->
        </div>
    </div>
</section>
{% endif %}

{% if this.theme.instafeed_about_page %}
<div class="instagram-section">
    <h6>Instagram Feed</h6>
    <div id="instafeed" class="instagram-slider owl-carousel"></div>
</div>
{% endif %}
LukeTowers commented 1 year ago

What plugins do you have installed and what versions are they?

01Kuzma commented 1 year ago

The php: list gives this list:

+--------------------------+---------+-----------------+----------------+
| Plugin name              | Version | Updates enabled | Plugin enabled |
+--------------------------+---------+-----------------+----------------+
| Winter.Blog              | 2.1.2   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| Vdlp.Phast               | 2.0.1   | No              | No             |
+--------------------------+---------+-----------------+----------------+
| AndreiShilov.Up          | 1.0.2   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| RainLab.BlogVideo        | 1.1.2   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| Martin.Forms             | 1.5.1   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| Romanov.ClearCacheWidget | 1.3.2   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| OFFLINE.ResponsiveImages | 2.5.6   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| OFFLINE.SiteSearch       | 1.5.6   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| RainLab.Pages            | 1.5.8   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| Winter.User              | 2.1.0   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| SureSoftware.PowerSEO    | 2.1.2   | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| OFFLINE.Speedy           | 1.0.11  | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| JanVince.SmallGDPR       | 1.21.0  | No              | Yes            |
+--------------------------+---------+-----------------+----------------+
| Winter.Pages             | 2.1.2   | Yes             | Yes            |
+--------------------------+---------+-----------------+----------------+
| Winter.Sitemap           | 2.0.2   | Yes             | Yes            |
+--------------------------+---------+-----------------+----------------+
| Winter.SEO               | 1.0.0   | Yes             | No             |
+--------------------------+---------+-----------------+----------------+
01Kuzma commented 1 year ago

I've forgotot to post a screenshot, maybe this will help: image

LukeTowers commented 1 year ago

If you downgrade Winter.Blog to v2.1.1 does that solve the issue?

composer require wintercms/wn-blog-plugin:v2.1.1

01Kuzma commented 1 year ago

@LukeTowers , thank you for the command :) Well, here is a downgrade error: image

composer.json has this part with requirements, if I understand it correctly:

    "require": {
        "php": "^8.0.2",
        "winter/storm": "dev-develop as 1.2",
        "winter/wn-system-module": "dev-develop",
        "winter/wn-backend-module": "dev-develop",
        "winter/wn-cms-module": "dev-develop",
        "laravel/framework": "^9.1",
        "wikimedia/composer-merge-plugin": "~2.0.1",
        "offline/oc-responsiveimages-plugin": "dev-develop",
        "winter/wn-blog-plugin": "^2.1",
        "winter/wn-pages-plugin": "^2.1",
        "winter/wn-sitemap-plugin": "^2.0",
        "winter/wn-user-plugin": "^2.0",
        "winter/wn-seo-plugin": "dev-main"
    },
TheFehr commented 1 year ago

If you downgrade Winter.Blog to v2.1.1 does that solve the issue?

composer require wintercms/wn-blog-plugin:v2.1.1

The command should probably be composer require winter/wn-blog-plugin:v2.1.1

01Kuzma commented 1 year ago

@TheFehr , thanks! Yes, it solves the issue. Now the error is gone

LukeTowers commented 1 year ago

@mjauvin I think this issue is caused by the recent refactoring / improvements, are you able to replicate this at all?

mjauvin commented 1 year ago

Sorry, can't reproduce this.

LukeTowers commented 1 year ago

@01Kuzma are you able to upload a basic version of your theme that contains just enough to replicate this issue in a fresh install of the winter develop branch and the latest blog plugin?

LukeTowers commented 1 year ago

@petehalverson side note, would really love to have Octodock back in some capacity 😉

01Kuzma commented 1 year ago

@LukeTowers I will try my best WebInstaller won't work in this way? Composer version only?

01Kuzma commented 1 year ago

Maybe this one will help... [removed]

mjauvin commented 1 year ago

I tried your theme, but it is in an unuseable state, plugins/partials missing, layout half beaten to death...

I managed to remove cruft to make it work, and didn't get the error you reported.

Please submit a theme in a usable state and a procedure to replicate your issue with it.

01Kuzma commented 1 year ago

@mjauvin , that's strange. I'm getting some other errors with it, the frontend even is not loading throwing errors... OK, I will try to remake it.

01Kuzma commented 1 year ago

@mjauvin I've reviewed it, I don't know what to upload, because the theme is image dependent (pulls them from storage), without them, it looks empty (as you probably saw it). I've just removed the partials with private information and excessive templates.

Removing the component form the page , of course, removes this error. But I have another one, accessing page Portfolio with two components: Post list & Category List gives this: image

Removing the Category List removes the error.

mjauvin commented 1 year ago

Can you show your Portfolio page ? Specifically, the url and the blogCategories component settings ?

I use this component without any problems on my latest website.

mjauvin commented 1 year ago

@LukeTowers I was able to generate an error with the blogCategories component when setting an invalid slug to the component slug property. What generates the error is this change:

-    public $currentCategorySlug;
+    public string $currentCategorySlug = '';

PHP now throws an error if you assign null to this Class property because it now expects a string.

So basically, if you have the following page/component settings, it will throw an error:

url = /blog/:slug
layout = default

[blogCategories]
slug = "{{ :invalidSlug }}"
categoryPage = "blog"
==

Notice the {{ :invalidSlug }} assigned to the component's slug property when it should be {{ :slug }}

I suspect it's possible to trigger similar errors in other blog components as well because of the extra property validation that was added. This is not necessarily a bad thing, but might break badly written themes.

01Kuzma commented 1 year ago

@mjauvin , here it is:

title = "Portfolio"
url = "/portfolio/:page?"
layout = "default"
meta_description = "Desc..."
is_hidden = 0

[blogPosts]
pageNumber = "{{ :page }}"
categoryFilter = "{{ :slug }}"
postsPerPage = 10
noPostsMessage = "Įrašų nerasta"
sortOrder = "published_at desc"
categoryPage = "blog-category"
postPage = "blog-post"

[blogCategories]
slug = "{{ :slug }}"
displayEmpty = 0
categoryPage = "blog-category"
==
{% set posts = blogPosts.posts %}
mjauvin commented 1 year ago

Just change:

[blogCategories]
slug = "{{ :slug }}"

To:

[blogCategories]
slug = "{{ :page }}"

To solve your issue.

mjauvin commented 1 year ago

@LukeTowers should we change the component like this to restore original behavior ?

diff --git a/components/Categories.php b/components/Categories.php
index 10a958c..b0609e3 100644
--- a/components/Categories.php
+++ b/components/Categories.php
@@ -17,12 +17,12 @@ class Categories extends ComponentBase
     /**
      * Reference to the page name for linking to categories.
      */
-    public string $categoryPage = '';
+    public ?string $categoryPage = '';

     /**
      * Reference to the current category slug.
      */
-    public string $currentCategorySlug = '';
+    public ?string $currentCategorySlug = '';

     public function componentDetails(): array
     {
01Kuzma commented 1 year ago

@mjauvin it solves the portfolio issue. Thank you! Why did this happen? I've created this theme long time ago based on some tutorials, as I remember

And how to fix the main problem? What should I change here? "\partials\intro.htm" at line 3. is pointing to hero-slider/hero1.htm with Post List component, which is:

[viewBag]

[blogPosts]
pageNumber = "{{ :page }}"
postsPerPage = 7
noPostsMessage = "No posts found"
sortOrder = "random"
categoryPage = "about"
postPage = "blog-post"
==
<div class="hero-slider owl-carousel">
    {% for post in posts %}
    <div>
        {% for image in post.featured_images|slice(0,1) %}
        <div class="hero-item portfolio-item set-bg lazyload" data-setbg="{{ image.path | resize(600,600) }}">
            <a href="{{ post.url }}" class="hero-link">
                <h4>{{ post.title }}</h4>
            </a>
        </div>
        {% endfor %}

    </div>
    {% endfor %}
</div>
mjauvin commented 1 year ago

@mjauvin it solves the portfolio issue. Thank you! Why did this happen? I've created this theme long time ago based on some tutorials, as I remember

It happens because there are errors in your theme and the last update to the plugin introduced property validation for the components.

And how to fix the main problem? What should I change here? "\partials\intro.htm" at line 3. is pointing to hero-slider/hero1.htm with Post List component, which is:

Please, always give the full settings section of the page you ask help for, otherwise it's hard to help.

[viewBag]

[blogPosts]
pageNumber = "{{ :page }}"
postsPerPage = 7
noPostsMessage = "No posts found"
sortOrder = "random"
categoryPage = "about"
postPage = "blog-post"
==
01Kuzma commented 1 year ago

@mjauvin , sorry, have edited the last post