OK, so here’s a way. Here’s a page where I extract the user’s name from the URL and then search for them:
A couple things to note:
- You can’t just have myapp.com/FirstnameLastname
- But you can have 应用宝官网-全网最新最热手机应用游戏下载
- (Aside: you can’t have 应用宝官网-全网最新最热手机应用游戏下载 as that seems to be a reserved word and Bubble gives a funny error message when you try to create a page with that name.)
- For the technique I’m about to describe to work, the User First Name and User Last Name fields MUST start with capital letters as the capital letters are used in this case as delimiters. You could get around this by extracting the name differently. For example, you could give folks the URL: 应用宝官网-全网最新最热手机应用游戏下载 (and this is really easy to extract without regex, right?)
Anyway, here’s how I set this up:
Here’s the on page load workflow:
This gets a little confusing because the page’s name is “users” – don’t let that throw you in the next screenshots!
First, let’s get the path. In my example page, this will return “KeithCrosley” and we shove that into a custom state I’ve created on the page object (which is named “users”):
Second, we extract the first name from the path. In my example, this will return “Keith” and shove that into another custom state on the page object (which again is named “users”):
^^^ I suck at Regex, so perhaps there’s a better way to do this, but this regex works for getting the first name (the string from the first capital letter up to the second capital letter). Also, I don’t quite understand why this regex returns a list… But no problem, we just take the first item in it.
Third, we can just use Bubble’s text manipulation functions to extract the last name. In my example, this will return “Crosley” and we shove that into another custom state (just for clarity and simplicity, right?):
^^^ you should understand that what we’re doing here is just snipping “Keith” out of “KeithCrosley” and leaving “Crosley”. Get it?
Now that we have a First Name and Last Name, we can “Do a search for… Users” with those parameters and grab one of them. Again, I’m taking that User object and shoving it in a custom state on the page object:
Of course, there COULD be multiple users with the same first and last names and so, if you really wanted to do things this way, you might have to have extra logic that disambiguates multiple users. For example, you could throw up a pop up or something. But what I chose to do here is simply take the first created user (the one with the earliest creation date).
For clarity, here is what the custom states on my page object look like in the inspector:
So, any user we know the name of we can display a profile page for. There’s a user in my test database called “Jennifer Hexagon”. Here would be her profile page:
Of course, there may NOT be a user with a name that we throw into the URL. Perhaps we should put up a message if so. You could do that with a condition or whatever. Like:
And so, if I don’t have a User named “Funky McChicken”, this page will show:
Anyway, this is pretty neat.