How to display USER fields on the front end

hi there we have a code on the old test site that worked perfect

{if $auth.user_id}
{assign var="user_data" value=$auth.user_id|fn_get_user_info}
{$lang.sub_balance} <br>You have $&nbsp;{$user_data.fields.36},  left of {$user_data.company} Subsidy</br>

{/if}

but we installed the 4.17 version as the trial and this is throwing all kinds of errors.
What has changed that this no longer works?
the error message on the bright template is

Syntax error in template "string:{if $auth.user_id} {if $user_info.firstn..." on line 9 "{assign var="user_data" value=$auth.user_id|fn_get_user_info}" modifier 'fn_get_user_info' not allowed by security setting


no clue what it means or how to fix this before the server gets moved to php 8.1

You can use controller for creating the $user_data variable and pass to template on the page where you need it

...

$user_data = [];

if(!empty($auth['user_id'])){
    $user_data = fn_get_user_info($auth['user_id']);
}

Tygh::$app['view']->assign('user_data', $user_data);

...

and remove from template

{assign var="user_data" value=$auth.user_id|fn_get_user_info}

Thank you
I put this in func.php in my_changes folder and removed the line {assign var="user_data" value=$auth.user_id|fn_get_user_info} that has removed the error from the template but still isn’t showing any of the users information

This is the code in the template and the fields are still blank on the front end

{if $auth.user_id}

{$lang.sub_balance} <br><b>You have $&nbsp;{$user_data.fields.36},  Left of the current {$user_data.company} Subsidy</b></br>
{/if}</p>

maybe I’m missing something

Should be added into a controller, and this depends on what page will be displayed

for ex. to be displayed on all the pages

Add into the file - app/addons/my_changes/controllers/frontend/init.post.php

*if the file is missing please create

<?php

use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

$user_data = [];

if(!empty(Tygh::$app['session']['auth']['user_id'])){
    $user_data = fn_get_user_info(Tygh::$app['session']['auth']['user_id']);
}

Tygh::$app['view']->assign('user_data', $user_data);

Thank you folks
I’ve added the controller as per your instructions and added this file app/addons/my_changes/controllers/frontend/init.post.php
and it still will not show the users data on the homepage after they log in

This code works to show the first name and last name and email address but it won’t show the company name. very strange to me!

{if $auth.user_id}
{if $user_info.firstname || $user_info.lastname }
{$lang.firstname}  {literal}<p style="background-color:rgba(232, 236, 241, 1);font-weight: bold;color:red;font-size:24px;">  
Welcome / Bonjour , {/literal}&nbsp;   {$user_info.firstname}&nbsp;  {$user_info.lastname} &nbsp;  {$user_info.email} &nbsp;  {$user_info.company} 
{/if}
{/if}

This is the code I’m using with your controller code and it doesn’t produce any thing on the block on the front page (homepage)

if $auth.user_id}

{$lang.sub_balance} {$user_info.fields.36} {$user_info.company} 
{/if}

these fields are blank on the template. but thank you for your on going help

The user_data variable name can be used somewhere in the code. Try to debug it

{$user_data|fn_print_r}

That just throws a security setting error

Syntax error in template "string:if $auth.user_id} {$user_data|fn_print_..." on line 3 "{$user_data|fn_print_r}" modifier 'fn_print_r' not allowed by security setting

this is the code in the block

if $auth.user_id}

{$user_data|fn_print_r}
{/if}

I took everything else out of the block just to make sure it wasn’t something else in the older code

case closed was able to figure out the security issue and the data is now being displayed in the template.

Thank you for all of your help!!!

Please clarify how did you fix it?

app/addons/my_changes/controllers/frontend/init.post.php file was permissions 644 had to change it to 666 for it to work for some reason

1 Like