Pass parameter to template with Smarty

Asked

Viewed 107 times

2

I’m reading the documentation from Smarty but I still can’t understand how I can and can pass parameter to a template using the Smarty.

I have this piece 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 body of this template.

Is there such a possibility?

1 answer

2


Yes, it is possible. Use the method assign() 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()

  • Thanks @rray, great help again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.