Help needed displaying dynamic pages differently

Hello, I just set up a dynamic page collection and connected page elements to a dataset.
I added a button to one of the pages in the collection and of course this button is displayed on all the pages of my collection.

  1. I would like to know if it is possible for this button to appear in just one (or a few) of the dynamic pages and not on all of them. If so is possible, how can I achieve this?

  2. I also connected this button’s text and click URL to data from a dataset and it works fine on all dynamic pages (it opens different links depending on the dynamic page it is situated on).
    My problem here is that the new page gets opened on a new tab while I want it to open on the same tab. I don’t see any option in the content manager that lets me specify this. On the database, I also tried adding a “rich text” field with one of the words being a link to another page but, again, when I click that link, the page opens in another tab.

  1. In theory, whatever you have on one dynamic page then you will have on all of them. You can get around this my hiding elements if there is no data for them for example and you can see more of that in previous posts like these.
    https://www.wix.com/corvid/forum/community-discussion/conditionally-show-button-on-dynamic-item-page
    https://www.wix.com/corvid/forum/community-discussion/hide-buttons-if-no-content
    https://www.wix.com/corvid/forum/community-discussion/how-to-hide-an-element-within-my-dynamic-page

  2. Look at using target to tell your link where to open.
    https://www.wix.com/corvid/reference/$w.LinkableMixin.html

Thanks a lot! I was able to solve both the issues.
I’ll paste here the code I used for people that might have the same issues:

  1. Code that lets you hide an element in a dynamic page if that element’s field in the database is not defined:
$w.onReady(function () {
    $w("#datasetName").onReady(()=>{
 if($w("#datasetName").getCurrentItem().datasetFieldName){
            $w("#button1").show();
        }
    });
});

In the element’s properties panel, select the “hidden on load” option.

Replace “#datasetName” with the name of your dataset:

Replace “.datasetFieldName” with the field key of the item you want to hide in case that field is left empty:


Replace “#button1” with the id of the item you want to show/hide.

  1. This is the code that lets the button open a link on the same tab:
$w.onReady(function () {
    $w("#button1").target = "_self";

});

where “#button1” is the id of the button element.