Personalizing Text

QuestionHi! I would love to create a daily personalized newsletter to my customers on their personal member profile page, where, for example, it says “Good Morning, {First Name}! I hope you’re having an amazing day.” (etc) In other words, on “Ricky’s” page it says, “Good Morning, Ricky!” etc. On Jennifer’s page, it says “Good Morning, Jennifer!” etc. I know how to create these custom fields that auto-populate with user info if I’m sending an actual email through Wix, but is there any way to use these custom field capabilities on a webpage?

I do know on a dynamic page if I created a text field I could change it manually for each person. But a) that would be pretty wonky in terms of how it looks formatted on the page b) would require me to go in to each member’s row every day

so that solution is not really viable.

Thank you! :smiley:

Product:
Wix Editor (or Wix Studio)

Do you want the same text, but just the name changed, or do you actually intend to customize the text for each user?

If it’s the former, you could do something like:

import { currentMember } from "wix-members-frontend";

currentMember.getMember(options).then(member => 
    $w('#personalizedText').text = 'Good morning ' + member.contactDetails.firstName + '!'
)

Thanks for the help, Dean!

Maybe further down the line it would be great to completely customize the text for each user, but to begin with, simply the {first name} where appropriate would suffice.

I’m not sure if the code you provided would do the trick or how I would implement it. I’m attaching a screenshot of just an example. Imagine I wanted the {Scout} to be replaced with the member’s name, as described previously. Then, also in certain additional places, within the main text, it would also say the first name. Like, it could also say “Anyway, {Scout} have a great time” and “Have a great day, {Scout}!” at the end.

I’m not sure how I would put a code if there are multiple places, and also if what’s on the page is intricate, i.e. text mixed with images and different formatting (bigger font, different-colored-font, etc) as you scroll down the page.

Thank you and hope for more wisdom!! :smiley:

The code I attached is used within the page code
You can enable that in the “Dev Mode” button on the top menu of your editor

import {currentMember} from 'wix-members-frontend'

currentMember.getMember().then(member => {
    // Within this function, 'member' is set to the data of the logged-in user
    const fname = member.contactDetails.firstName
    // Do whatever with the member details...
})

$w(tag) selects an element
For a text element (For example, #text1), you can set the .text property to change the text displayed

$w('#text1').text = 'Have a great day, ' + fname + '!'

You could manipulate any text element this way

This might not be very convenient for large pieces of test though…

Thanks so much Dean. I inserted the code but I’m getting an error message. See screenshot.

This seems to be appearing in many places recently, even without code changes

Have you made sure that you’re using the correct tags for whichever elements you’re selecting when using $w()?

Ah, I see the problem:
You have inserted the functional lines, but not the import (commented out in your code, and within a function as opposed to at the top of the file) so the page code does not recognize what currentMember is

I’m very sorry, I’m not sure what you mean. Could you provide the code on how to fix this/how it’s supposed to look? I don’t mean to be needy, in fact I like learning things…but I’m clueless on how to fix this issue. In the future I will look forward to fixing it myself. :sunglasses:

We all start somewhere :slight_smile:
My apologies if at any point I over-explain

// This is a comment
// nothing written here will be executed

You have commented out the import line in the code you pasted from me
Perhaps you pasted it instead of the your code goes here text that wix generates within the comment in the default page code?

The import line should be uncommented (Remove the //) and moved to the top of the file

Fantastic, it worked! I’m glad you pointed out a) the significance of using the // (I’ve always wondered about this) and b) the ‘import’ needs to go before any onReady stuff.

Question: I would love to walk through Wix’s coding capabilities and basically ‘pick your brain’ to see which things I’ve been dreaming of for my website are actually possible. I really need to just figure out the potential vs moving to Wordpress or a complete custom code from scratch. I would be happy to pay you for the session. Would you be interested?

Sure :slight_smile:

You can contact me through dev@deanayalon.com and we’ll set a meet when comfortable

Quite a lot can be done with the Velo API, and its various integrations.
Both platforms allow you to do almost anything, so unless you’re looking for some state-of-the-art obscure-behaving rocket-fast website, you’d probably be able to achieve your desires on either one, just a question of convenience

Great. I sent you an email right now just to make sure you receive it. Please respond to it. Thanks!