Tl ;dr. Get a nice looking list output, rather than the normal commas or line breaks.
I was searching around how to make my boring output look a little prettier. It was basically a list of things that outputted like this:
Yacht Ratings Certificate, PWCI, Navigation and Radar (OOW), Master 500gt (yacht), GMDSS (ROC)
I liked the thought of adding each list item to a tag display, but I couldn’t really find what I wanted here in the forum so I created something myself. I thought I would take a little time to jot down how I did this, and who knows, it might help someone else looking for the same thing too.
Initial (boring) list:
I knew I needed to insert some <div>
's and <span>
's for styling. Unfortunately, text elements don’t allow for these to be added /replaced. I replaced the text element with an HTML element. Here’s what I managed to output. Much better than the original text element could manage.
HTML element
The trick is to:
- Add a div before the dynamic data
- Use “join with” on the dynamic data using an end and start span
- Add a closing div after the dynamic data
By the way, I don’t normally have css on-page - it’s just for this post. Hopefully this helps someone
FYI, I changed the styling code slightly so it wraps the tags correctly:
.tag-list span {
padding: 2px 4px;
border: 1px dotted rgba(1, 176, 187, 0.65);
border-radius: 5px;
color: rgba(1, 176, 187, 1);
font-family: Roboto;
font-size: 12px;
margin: 0 5px 10px 0;
font-weight: 500;
display: inline-block;
word-wrap: break-word;
white-space: normal;
}