dvargas92495 / SmartBlocks

Useful examples from developer community for Roam42 SmartBlocks
147 stars 7 forks source link

Embed an image from Unsplash using random or query terms #152

Open mlava opened 3 years ago

mlava commented 3 years ago

✂️ Copy of your 42SmartBlock from Roam

📋 Describe the SmartBlock

This SmartBlock allows you to embed either a random image from Unsplash or define a query and embed an image matching that term. There is some minor configuration required: see the images below.

✅ Describe any prerequisites or dependencies that are required for this SmartBlock

You need to have a free account to access the Unsplash API. You can create one here.

Once signed up, you need to create a new application. The 'Demo' tier is probably enough as this allows up to 50 requests per hour.

Then, retrieve the Access Key from the Keys section in your Application settings as you need to enter this in the configuration as shown below.

You need to create a configuration section as below and complete using your desired settings. There are two mandatory settings and several optional ones.

- **Unsplash SmartBlock Configuration:**
    - **Mandatory Settings:**
        - *** Access Key:**
            - <Enter Access Key here>
        - *** Preferred Search Mode:**    __(QUERY | RANDOM)__
            - <Enter QUERY or RANDOM here>
    - **Optional Settings:**
        - **Default Query:**    __(preferred default search term for prompt)__
            - relaxed
        - **Width:**    __(in pixels)__
            - 600
        - **Display:**    __(LANDSCAPE | PORTRAIT | SQUARISH)__
            LANDSCAPE 

Note that your configuration section can go anywhere in your Roam graph. I have mine placed below the SmartBlock on the same page, but not as a sub-block!

You need the Access Key from your Unsplash settings to enter in the sub-block shown in place of . Then, type RANDOM or QUERY in the Preferred Search Mode sub-block.

screenshot 10

The default query is only needed if mode is QUERY. Width and Display mode are not required but can be set if preferred.

Once you've set your configuration, you need to update each of the <%SET:accessKey,<%RESOLVEBLOCKREF:(())%>%> statements in the second block shown here:

image

Replace each block reference with the block ref in your own configuration section.

📷 Screenshot of your 42SmartBlock workflow/template from Roam

screenshot 8 screenshot 9

💡 Additional Info

Video Demonstration: https://www.loom.com/share/9aa25246fbfa4eed9f498fe2abebf667


[label_example]