DappHero Docs
  • Getting Started 👋🏽
  • DappHero Basics
    • How does it work? 🧐
    • Setting Up Your Project 🏗️
      • Projects
      • Smart Contracts
    • An Intro to Features 🎁
  • Features
    • Network ⛓️
    • User 🤖
    • 3box 👯‍♂️
    • Smart Contracts 👩🏾‍🔬
      • Adding Smart Contracts 🏗️
        • Contract Details
      • Create a Method Instance
      • Inputs
      • Invoke
      • Outputs
      • Events
      • Advanced: Automatically clearing Inputs
      • Advanced: Getting the Current User's Address Dynamically
      • Advanced: Sending ETH to a contract method
      • Listening to Events
      • Resources: Learn More
      • Resources: Test Contracts
    • Collectibles 🃏
      • Getting Started
      • Single Collectibles
      • Listing Collectibles
      • Displaying Token Metadata
      • Advanced: $CURRENT_USER
      • Advanced: $URL
      • Advanced: $THIS
      • Advanced: Properties
      • Calling Smart Contracts inside Collectibles
      • Collectible Example
  • No-Code Integrations
    • Webflow 🎁
      • Getting Started with Webflow
      • Add DappHero Elements
      • Learn more about WebFlow
  • Examples
    • Coming soon...
  • Advanced
    • Engine Events
    • Force Refresh
    • Database
    • Ethereum Provider
  • Updates
    • ChangeLog
  • Bug Bounty
Powered by GitBook
On this page
  • Usage
  • Example
  • Forms

Was this helpful?

  1. Features
  2. Collectibles 🃏

Advanced: $THIS

Referring to the current Collectible's information

PreviousAdvanced: $URLNextAdvanced: Properties

Last updated 4 years ago

Was this helpful?

This documentation is unfinished

Advanced features such as , or referencing the are important to building dynamic functionality for Collectibles. To complete this functionality and give users the ability to dynamically generate links from Collectibles in a list to a page of a single collectible, we have created the ability for an HTML block to dynamic reference itself with the const $THIS...

Usage

The $THIS... const is useful when it is necessary to refer to the current item, for example when creating dynamic links that should be unique for each collectible item.

CONST

Purpose

$THIS_ContractAddress

Substituted with current Contract Address

$THIS_TokenID

Substituted with current TokenID

$THIS_OwnerAddress

Substitutes with current OwnerAddress

Example

For a live Demo: .

Suppose you wanted to build a webpage that showed a dynamic list of Collectibles based on the contract address of a particular NFT contract. This is fairly easy to do, . Now let's say you wrap each Token's image in an anchor tag, turning the image itself into a link that when clicked upon takes the user to a new webpage that shows a . Creating a Single Collectible is also fairly easy, but the question is- how would you pass the data about WHICH collectible you want to display on the Single Collectible page?

This is where we use $THIS...

<div
      data-dh-feature="nft"
      data-dh-property-tag-id="000"
      data-dh-property-asset-contract-address="<<contractAddress>>">
     
   <div
      data-dh-property-tag-id="000"
      data-dh-property-asset-item="true">
      <a
         href="./singleNFT.html?assetTokenId=$THIS_TokenID&assetContractAddress=$THIS_ContractAddress">
         <img data-dh-property-asset-json-path="image_url"/>
         </a>
     </div></div>

Let us take a closer look at line 9-12. What we are doing here is creating a link to a new page but passing URL Query Params for the DappHero engine to catch in the singleNFT.html page. You could manually pass the details assetTokenId=1234 but then you would be stuck always rendering this one token. Instead, because we are inside the asset container from line 6-9 which gets rendered for each Collectible returned, we can access THIS specific token. If we use $THIS_TokenID in the href link, it will get replaced with the token currently displayed, for example '1234'. If we do the same for the assetContractAddress we can now link to the singleNFT.html page passing all the information required for that page to render dynamically the specific collectible token we are interested in.

<a
href="./singleNFT.html?assetTokenId=$THIS_TokenID&assetContractAddress=$THIS_ContractAddress">
<img data-dh-property-asset-json-path="image_url"/>
</a>

Forms

Using the $THIS... const is useful for more than just creating dynamic links- it can also be used to create dynamic forms. This means you can combine the Collectible feature with other features like smart contracts- allowing users to interact with smart contracts using the about the current token they are looking for. A great example for this would be to create a Collectible store front connected to a smart contract to let people buy or sell Collectibles directly from your website!

Have a look at this simple example.

<form action="">
        TokenID: <input type="text" value="$THIS_TokenID"><br><br>
        Owner Address: <input type="text" value="$THIS_OwnerAddress"><br><br>
        <input type="submit" value="Submit">
</form> 

getting parameters from the URL bar
current user
DappHero-nft-example
Single Collectible
list the Collectibles