Pass parameter to template with Smarty

2

I'm reading the documentation for Smarty but I still can not understand how I can and can pass parameter to a template using Smarty .

I have this snippet of code:

if ($part == PagePart::RecordCard && ($mode == PageMode::View || $mode === PageMode::ExportPdf)) {

    $cpf = GetApplication()->GetGETValue('pk0');

    $sql = "SELECT Opcao FROM dvsDecModelo WHERE CPF = '$cpf' ";
    $Opcao = $this->GetConnection()->ExecScalarSQL($sql);

    if ($Opcao == "Contrato") {
        $result = $mode === PageMode::ExportPdf ? 'TempModelo1Pdf.tpl' : '';
    } elseif($Opcao == "Adesão") {
        $result = $mode === PageMode::ExportPdf ? 'TempModelo2Pdf.tpl' : '';
    } else {
        $result = $mode === PageMode::ExportPdf ? 'TempModelo2Pdf.tpl' : '';
    }
}

Now, in my case, I need to pass the result of a query to the template, retrieve it and use it in the template body.

Is there a possibility?

    
asked by anonymous 09.04.2018 / 16:43

1 answer

2

Yes, it is possible. Use the assign() method of the smarty two arguments are passed the first is identifier which value will have and the second the value itself.

$template->assign('lista', $modelos);

Documentation - assign ()

    
09.04.2018 / 16:55