hello everyone
I want to add dynamic page link to a button… I did like this but it is still not working …
when I click the button it must check the collection and get the user email , then add it in the link… however the button is not working
![](https://global.discourse-cdn.com/wix/original/3X/d/3/d344927bfbff85def98fc545e24fc334c9fe0928.png)
the code is like this :
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
export function button1_click(event, $w) {
wixData.query("student")
.find()
.then( (results) => {
let firstItem = results.items[0];
wixLocation.to(/student/info/
+firstItem.pemail);
} )
. catch ( (err) => {
let errorMsg = err;
} );
}
Hi Warda,
Few things you should be aware of:
First, Be sure that the link path for the dynamic page is correct.
Second, i think you are missing the most important part in your query, which is the current user that you want his Email, because in your code seems to return always the first item from the database, Right?
So what you should do is to add a query that finds the current user then get his email then you can added to the link ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/google_classic/slight_smile.png?v=12)
For more information, check this Wix Api - HERE
Hope this helps!
Best,
Mustafa
hello @mhammouz
thanks for your help,
I changed the code , I think it’s better to get the current user’s email instead of checking the database so I make it like this but it is still not working , can you please tell me where is the problem?
export function button1_click() {
//Add your code for this event here:
let user = wixUsers.currentUser;
user.getEmail()
.then( (email) => {
let userEmail = email;
wixLocation.to(/student/info/userEmail
);
} );
}
I get this error that the page is not here and in the url instead of the current user’s email I just get (userEmail) word
I solved the problem :
instead of writing the UserEmail in the string
wixLocation.to (/student/info/userEmail
);
it must be like this:-
wixLocation.to (`/student/info/’ + userEmail);
![:slight_smile: :slight_smile:](/images/emoji/google_classic/slight_smile.png?v=12)
It is not – wixLocation.to (`/student/info/’ + userEmail);
It is – wixLocation.to (/student/info/
+ userEmail);
Eagle-eye-Ajit! ![:grin: :grin:](/images/emoji/google_classic/grin.png?v=12)
But what you did not see is the DATE of this post ^^
I don’t think taht the post-opener still wants to know the aswer/solution.![:grin: :grin:](/images/emoji/google_classic/grin.png?v=12)
i am new at wix i want to create a custom button which will lead users to another website blog section in sidebar but i don , t know how to do so should i hire someone to do so becasue it require HTML