Problemas com o foreach

ola estou no capitulo 6.2/6.3 porem quando vou imprimir na tela isto aparece !
Notice* : Undefined variable: lista_tarefas in C:\xampp\htdocs\Livro PHP&MYSQL\Tarefas\template.php on line 64

Warning : Invalid argument supplied for foreach() in C:\xampp\htdocs\Livro PHP&MYSQL\Tarefas\template.php on line 64

segue o codigo :
template.php

<?php date_default_timezone_set('America/Sao_Paulo'); ?> Gerenciador de tarefas

Gerenciador de Tarefas

Tarefa:
            <input type="text" name="nome"/>
        </label>
    <label> Descrição:
        <textarea name="descricao"></textarea>
        </label>
    <label>Prazo:
        <input type="text" name="prazo">
        </label>
    <fieldset>
        <legend> Prioridade: </legend>
        <label>
            <input type="radio" name="prioridade" value="baixa" checked> Baixa
            
            <input type="radio" name="prioridade" value="media" > Media
            
            <input type="radio" name="prioridade" value="alta"> Alta
        </label>
    </fieldset>
    <label>
         <fieldset>
        Tarefa concluida: 
        <input type="checkbox" name="concluida" value="sim">
        <input type="submit" value="Cadastrar" /> 
         </fieldset>
    </label>
</fieldset>
<table>
    <tr>
        <th>tarefas:</th>
        <th>Descricão:</th>
        <th>Prazo:</th>
        <th>Prioridade:</th>
        <th>Concluida:</th>
    </tr>
 <?php   foreach($lista_tarefas as $tarefa) :?>
    
    <tr>
        <td><?php echo $tarefa['nome']; ?> </td>
        <td><?php echo $tarefa['descricao']; ?> </td>
        <td><?php echo $tarefa['prazo']; ?> </td>
        <td><?php echo $tarefa['prioridade']; ?> </td>
        <td><?php echo $tarefa['concluida']; ?> </td>
    </tr>
    <?php     endforeach; ?>

</table>

segue tarefa.php

<?php session_start(); if (array_key_exists('nome', $_GET) && $_GET['nome'] != '') { $tarefa = []; $tarefa['nome'] = $_GET['nome']; if(array_key_exists('descricao', $_GET)){ $tarefa['descricao'] = $_GET['descricao']; } else { $tarefa['descricao'] = ''; } if(array_key_exists('prazo', $_GET)){ $tarefa['prazo'] = $_GET['prazo']; } else { $tarefa['prazo'] = ''; } $tarefa['prioridade'] = $_GET['prioridade']; if(array_key_exists('concluida', $_GET)){ $tarefa['concluida'] = $_GET['concluida']; } else { $tarefa['concluida'] = ''; } $_SESSION['lista_tarefas'][] = $tarefa; } include("template.php"); ?>

Olá, @Renatorvs.

A variável $lista_tarefas não foi definida no arquivo tarefa.php. Antes de incluir o template você precisa definir esta variável.

olá fiz oq sugeriu, porem aparece o mesmo problema, segui exatamente o que estava no livro, segue o codigo tarefas.php

<?php session_start(); if (array_key_exists('nome', $_GET) && $_GET['nome'] != '') { $tarefa = []; $tarefa['nome'] = $_GET['nome']; if (array_key_exists('descricao', $_GET)) { $tarefa['descricao'] = $_GET['descricao']; } else { $tarefa['descricao'] = ''; } if (array_key_exists('prazo', $_GET)) { $tarefa['prazo'] = $_GET['prazo']; } else { $tarefa['prazo'] = ''; } $tarefa['prioridade'] = $_GET['prioridade']; if (array_key_exists('concluida', $_GET)) { $tarefa['concluida'] = $_GET['concluida']; } else { $tarefa['concluida'] = ''; } $_SESSION['lista_tarefas'][] = $tarefa; } $lista_tarefas; // variavel que foi sugerida pelo forum include"template.php"; ?>

Mas você não está atribuindo um valor à variável.

Tente $lista_tarefas = $_SESSION['lista_tarefas'];