How to show logged in user's name in the website

How would you change this to pull in another field from the Users Airtable table?

1 Like

Like the above comment, I would also like to know how we can pull in other fields from Airtable. Or is it limited to just the name?

1 Like

Hi everyone,

I have followed Artur’s guide and it works perfectly for custom code blocks but not for other blocks though, such as “hero with CTA”. It usually works once and then it doesn’t when you refresh the page. I’ve tried to find a solution, without any success so far…

Here is the code I used:

<script>
    document.addEventListener("DOMContentLoaded", function () {
        if(window.logged_in_user) {
            const name = window.logged_in_user.softr_user_full_name;
            $("span:contains('{LOGGED_IN_USER:NAME}')").removeClass('student-name');
            $("span:contains('{LOGGED_IN_USER:NAME}')").html(name);
        }
    });
</script>

Here is a screenshot of the two different blocks, you can see that it’s working for the first one (custom code) but not for the second one.

Does anyone know how to solve this issue?

Thanks for your time! :slight_smile:

@Theo use the code below:

<script>
window.addEventListener('block-loaded-blockname1', () => {
	console.log('Block loaded');
    if(window.logged_in_user) {
        const name = window.logged_in_user.softr_user_full_name;
        $("span:contains('{LOGGED_IN_USER:NAME}')").removeClass('student-name');
        $("span:contains('{LOGGED_IN_USER:NAME}')").html(name);
    }
});
</script>

blockname1 - needs to be your block’s name as shown in the studio settings see the pic below.

1 Like

It worked! Thanks a lot @artur! :blush:

Lookng for this. How to pull another airtable field?

Hi @meenal.malhotra, you can check this one :star_struck:

Hi everyone now this feature is super simplified in Softr. You just need to place the {LOGGED_IN_USER:NAME} placeholder in the corresponding field and it will display the user’s name in preview. Enjoy :star_struck:

Is there documentation of local variables we can reference like this?