Improving your homepage
In this tutorial, we're going to make your home page look like this:
Also, the main banner image will randomly switch between two images!
Adding the banner
Creating a Data² Drive
To upload and use an image we will use the Data² Drive. To add a Data² Drive:
- Double-click on the Builder background.
- In the menu that appears, select
Mediain the left tab. - Click on
Drive. - If necessary, resize and reposition your Drive.
- Rename your Drive.
Uploading an image to the Data² Drive
Since I really like coffee, I'm going to use this image as the homepage banner. Drag your image into Drive to upload it.
Using the image in the Block
First, select the Block with the Homepage text that was created earlier. Then look for the Fill parameter, select Image, select the Drive that was created and the image that is there.
In the image options, put the following settings:
Size:CoverPosition X:CenterPosition Y:BottomRepeat:No Repeat
Double-click the Block to delete the Homepage text and adjust the Block size if necessary.
Adding a text
Use the Block Tool (shortcut: B) to draw a Block which will be used to place a callout text on top of the image.
Double click on Block and write the text you want, in this case, I decided to write The best coffee. Increase the font size by changing the Text Size parameter to 48. Disable Fill by clicking on the circle next to its title.
In Text Format, center the text vertically by clicking on the third button in the second row. Set the Font Weight parameter to Bold and Text Transform to UPPERCASE. Then place your Block with the text.
Block dimensions for different screen sizes
If your resolution is not the same as the Artboard, there is a very obvious problem with our banner: its size.
Banner on artboard:
Banner on preview:
To solve this, let's understand the Position parameter constraints.
Select the banner block with the image, look for the Position parameter and click on Grow Horizontally and Grow Vertically. Preview your Artboard and see how it turned out.
Each line outside the square is a constraint, and indicates that if that constraint is activated, the distance for that direction will be maintained.
To better understand how constraints work, select the Block with the link to the customer administration page, and click on two restrictions: top and left.
In the video above, the Block maintains a fixed distance from the top and left of the screen, that is, as the screen increases in size (by zooming out), the Block moves upwards because even though the total height screen has grown, the distance to the top remains.
Placing a conditional banner
A very powerful feature of Data² is being able to change the type of parameters. What this means in practice is that many things that could only be solved with code, can be solved with Data².
Let's turn the banner image into a conditional value, for that:
- Copy the current value of
Fillby clicking on the...button, and in the menu that pops up, click onCopy param to clipboard - Then click on the button with
f()and change the type toIf. - Click on
Fillto navigate, and in theThenparameter, paste the previousFill, opening the menu and clicking onPaste param from clipboard. In this step, the browser may ask for your permission to access what was copied, approve it so that you can successfully paste the parameter. - In the
Elseparameter, click onf()and selectFill. - Put a color as background.
- Now click on
Compare, add an item by clicking onAdd Item. - Click on
f()and change the type of this item toBoolean. - When changing the toggle button value, the backgrounds will alternate!
What is a conditional value?
A value that is attached to a clause, and has different values depending on whether the clause is true or false is a conditional value. For example, the shelf life of a food is a conditional value of the current date and the shelf life:
`If` the current date is before the expiry date, `Then` you can eat it, `Else` it's expired and you shouldn't have it.
Now, let's put this image in the Color place, and use a random number to switch between these two backgrounds.
- Click
Fillto navigate. - In the
Elseparameter, click onImage. - Select the
Drive, click to select the file, and drag your image to the Drive. - When finished sending, select that image.
- Configure image options:
Size:CoverPosition X:CenterPosition Y:CenterRepeat:No Repeat
- Click on
Compare, on the item whose type wasBoolean, click on thef()button to change the type toEqualOrGreaterThan. - Click on the first item to navigate.
- In the
Subjectparameter, click on thef()and selectMathRandom. This type returns a random number between 0 and 1. - In the
Comparison Subjectparameter, put0.5.
This means that every time you enter the homepage, the user will se a different banner that will alternate with the same ratio!