Skip to content
Grav 2.0 is officially stable. Read the announcement →
Themes & Styling

An exception has been thrown during the rendering of a template ("Array to string conversion") after upgrade

theme

Started by Kalimati 5 years ago · 4 replies · 1877 views
5 years ago

Hi,

I have upgraded and old Grav website from version 0.9 to 1.7. Most of it works except for one page.

Screenshot from 2021-12-07 20-26-41|690x485

HTML
<div class="modular-row team">
    {{ content|raw }}
    <div class="members">
        {% for member in page.header.members %}
        <div class="member">
            <img src="{{page.media[member.image].url}}" alt="">
            <h4>{{ member.name }}</h4>
            <span>{{ member.title }}</span>
            <hr>
            <p>{{ member.info }}</p>
            <ul class="social-icons">
                <li>
                    <a href="{{ member.social_twitter }}">
                        <i class="fa fa-twitter"></i></a>
                </li>
                <li>
                    <a href="{{ member.social_facebook }}">
                        <i class="fa fa-facebook"></i></a>
                </li>
                <li>
                    <a href="{{ member.social_feed }}">
                        <i class="fa fa-rss"></i></a>
                </li>
            </ul>
        </div>
        {% endfor %}
    </div>
    <div class="callout-line"></div>
</div>
YAML
---
title: Team
menu: false
members:
    - name: NETWORK, TELECOM, AUTOMATION ENGG.
      image: structured-cabling.jpg
      info: 
        - "Network Administration and Implementation,"
        - "Automation & Instrumentation,"
        - "Telecommunication Engineering,"
        - "CCTV Camera Security System."
    - name: IT SERVICES
      image: software-code.jpg
      info: 
        - "Facility Management, Call Centers, Helpdesk"
        - "Technical Support, Data Entry,"
        - "Managing Business Processes"
        - "Data Base Administration (Oracle)"
        - "Software Development, Training & maintenance"
    - name: ENGG. PROJECTS & CONSTRUCTIONS
      image: optic-fibre.jpg
      info: 
        - "Engineering Projects & Construction,"
        - "Specialised Technical Consultancy – Engineering & Projects,"
        - "Irrigation and Water Distribution System (HDPE)"
---
## What Do We Do?
We specialize in providing a wide range of IT and engineering services. Executing projects and tasks with high standards of quality, innovation and dedication.
5 years ago

@kalimati:

YAML
      info: 
        - "Network Administration and Implementation,"
        - "Automation & Instrumentation,"
        - "Telecommunication Engineering,"
        - "CCTV Camera Security System."

Your {{ member.info }} is an array, but template tries to display it as a string.
There are several ways to fix this (like iterating the array and displaying each element on its own), but the easiest would be:

TWIG
{{ member.info|join(' ') }}

I think space fits here, because you already have commas in your info strings

👍 1
5 years ago

Actually I would like to display the "info:" array as an unordered list.

5 years ago

@kalimati, Beware that theme Deliver is not compatible with Grav 1.7. Template /partials/simplesearch_base.html.twig does not render assets correctly:

Filter |raw should be added.

👍 1
5 years ago

Then something like

TWIG
{% if member.info|length %}
  <p>
    <ul>
      {% for info in member.info %}
        <li>{{ info }}</li>
      {% endfor %}
    </ul>
  </p>
{% endif %}

But keep in mind what @pamtbaau mentioned about theme support

👍 1

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 226 2 months ago
Themes & Styling · by Ian, 2 months ago
3 119 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 483 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 73 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 152 3 months ago