'codeigniter tutorial - changing text color based on boolean
I am working on the codeigniter tutorial but my assignment now says to add a boolean row named "importance" to the database and set one of the news articles to true. Could someone point me in the right direction on how I would then change the title of the article to a different color when the row is set to true.
Below is my template of how I am displaying the stories. All I need to do is check the importance then change the color of the title. just not sure how to do that
<hr>
<br>
<h3>Title: {title}<br></h3>ID: {id}<br>
<br>{text}<br>
<button class = "btn">
<a class="text-dark" href="/news/{slug}"> Read more</a>
</button>
{/stories}```
Solution 1:[1]
I suppose you already returned the importance
variable to the view in your data array, so you would basically need to use it to change the color:
<h3 style="color:<?= $importance == true ? 'red' : 'green' ?>">Title: {title}</h3>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sherif Salah |