What I’m trying to do:
Create a custom component card with an image, headline, and sub-text. This can be then dropped multiple times on a landing page.
What I’ve tried and what’s not working:
I can create the custom component no problems. The problem is when I drop it onto the landing page. How can I load an image, its heading and its subtext into each component?
Clone link:
https://anvil.works/build#clone:GVO47M54HICNNKWT=BZES7TB3BSFFSNK3FVNYJXI5
You could also just create a blank form with those components on it and then add it to what ever form you want. Check out this in the docs
https://anvil.works/docs/client/components/forms
1 Like
Thanks for your links to the documentation. That helped.
Answer:
- Create a form
- place the components in the form
- in the init() of this form:
def __init__(self, **properties):
self.headline_1.text = properties["headline"]
self.image_1.source = properties["image"]
self.label_1.text = properties["text"]
# Set Form properties and Data Bindings.
self.init_components(**properties)
- over at the left menu, click the arrow next to file name
- “Use as component”
- Check the box “Make this form available as components”
- Add properties that match the keys of
properties
in 4) NOTE: use ICON for the image
Note: These are assigned during runtime
- drag this form into parent form
- in the design window, fill in the properties fields
- press “RUN”
1 Like