duda
How to build stunning widgets with the help of AI

Shawn Davis • Mar 21, 2024

For the vast majority of your small business clients, Duda has all of the widgets you need right out of the box. But what about your spendier, more particular clients? There are those out there who want a more bespoke experience for their website, and they’re willing to pay for it.


That’s where the HTML widget and the Widget Builder come into play. These tools give your agency the power to create entirely custom elements using regular HTML, CSS, and JavaScript. Many agencies already, especially Duda Experts, have already created fantastic widgets that push the limits of the Duda platform.


While some people might look at these powerful features with excitement, others undoubtedly view them with dread. Not everyone can be a developer, right? Well, that might not be the case anymore…


AI tools make coding more accessible


We’ve written before about how agencies can use artificial intelligence to increase their productivity, but something we haven’t quite touched on is how they can use it to expand their capabilities—particularly at the technical level.


AI tools like Gemini and ChatGPT make writing code, especially in wildly popular languages like HTML, much more accessible. Take this webinar we hosted in 2023 on using python for SEO as an example. In it, speaker Olesia Korobka uses ChatGPT to create quality python code in no-time.


You shouldn’t be surprised to hear that this process can be applied to widgets just as well. We’ll take this concept for a spin by using ChatGPT to create a simple, marquee style text scroller, like something you might see on the news, using the HTML widget. Then, we’ll transform it into something we can use over-and-over again on multiple client sites with the Widget Builder. The finished product will look something like this:



DUDA ROCKS


Creating HTML with ChatGPT



We’re going to be using ChatGPT, but feel free to use any AI tool you prefer. Like any good prompt, we first want to define a role for our AI. In this scenario, we want an expert web developer. Then, we describe what we’re looking for: a news-style scrolling text marquee. We’ll make the text “DUDA ROCKS,” separated by bullet points and repeating, for this example. Here’s out prompt:


AI prompt
You are an expert web developer with years of experience creating concise, high-quality code. Please write code within a code block that displays the text "DUDA ROCKS " as a responsive infinite marquee. Please separate the HTML and CSS into separate code blocks and do not include the <html> or <head> tags in the HTML portion.


Notice it gave us an answer conveniently within two distinct code blocks, one for HTML and one for CSS? Here’s what we got for HTML:

 

<div class="marquee-container">

  <div class="marquee">

    <span>DUDA ROCKS </span>

    <span>DUDA ROCKS </span>

  </div>

</div>

Next, our CSS:

 

.marquee-container {

  overflow: hidden;

  width: 100%;

}


.marquee {

  display: flex;

  animation: marquee-animation 10s linear infinite;

}


.marquee span {

  margin-right: 20px; /* Adjust as needed */

}


@keyframes marquee-animation {

  0% {

    transform: translateX(100%);

  }

  100% {

    transform: translateX(-100%);

  }

}


We can copy and paste this directly into the HTML widget by first pasting the HTML, then selecting “Edit CSS”, then pasting the CSS after the last bracket at the very end. That’s it!


While this looks great, it isn’t super reusable. Thankfully, that’s where the Widget Builder comes in.


Transforming HTML into a widget


While the Widget Builder may seem intimidating, understand that you do not need to be a developer to do what we’re about to do. That’s because the Widget Builder uses a simple form builder and intuitive “handlebars” to make code customizable.


We’ll start with the form builder, specifically the “Content Editor” tab within the Widget Builder. Select “+ Add Input” then, for the input type, choose “text.” This is going to be the text that goes within our marquee widget. For the descriptive label field we can replace “Text” with “Marquee Content” then, for the variable, replace “text1” with “marqueeText.” We should also go ahead and mark this as a required field.


We’re about a third of the way done already. Next, let’s switch over to the “Design Editor” tab and add an input here as well. For this one, we’ll select “Text Style” as the input type. Next, let’s type “.marquee-container” into the custom selector field. You should recognize this from the code that ChatGPT created. We can add another input, this time “Background,” and give it the same “.marquee-container” custom selector.


The Widget Builder does some magic here with the Design Editor. It’ll lock onto the design of any element labeled with the class “marquee-container” and will automatically apply font and background style to that element.

That leaves one more step—the code. Under the “Widget Code” section, select HTML. We’re going to paste our HTML into the editor here with one small modification—we’re going to replace “DUDA ROCKS” with “{{marqueeText}}” like so:


These are the handlebars we discussed. They’ll be automatically replaced with whatever text is submitted into the Content Editor before our widget is ever rendered.


Finally, we’ll just paste our CSS as-is into the css/scss section.


That’s it, our widget is ready to publish. Now we can customize the content, background color, an design, like so:



THANKS FOR READING


Looks great, huh?


What are you going to make?


Are you ready to use AI to build your own widgets? We’d love to see what you make! Share your creations with us and your fellow website builders in the Duda Community. We can’t wait to see what you build, or, in this case, generate.

Entrepreneur's logo and How to design an eye-catching website that truly captures your audience.
By Itai Sadan 24 Apr, 2024
The rules governing a "well-designed website" are in constant flux. So getting insights into the latest web design trends for 2024 is crucial to captivate visitors and engage the right audience for your business.
The homepage for Duda.co
By Renana Dar 22 Apr, 2024
We sat out to redesign Duda's homepage using the most advanced capabilities of our own platform. See how we combined design, code, and advanced drag-and-drop capabilities to create a homepage like no other.
Three cards with a picture of a chair on them
By Shawn Davis 19 Apr, 2024
There exists a maximum number your customers are willing to pay, but finding that number is no easy task. Here’s everything your SaaS company needs to know about uncovering this elusive metric.
Show More

Latest Posts

Share by: