We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Accessing status highlight color in templates

Development and Programming

Luke Sturgeon's avatar
Luke Sturgeon
17 posts
13 years ago
Luke Sturgeon's avatar Luke Sturgeon

I’m setting the colours etc for channel statuses in the back-end which work on the edit page fine. But I’d also like to use these colours dynamically on the front-end too.

I can get {status} in the channel entries loop. Is there any way to access additional information about the status such as colour?

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Hi Luke,

There isn’t any variable in channel entry tag to populate the status color. So you need to have conditions for it like:

{if status == 'open'}
class="color1"
{/if}

Best Regards,

       
Luke Sturgeon's avatar
Luke Sturgeon
17 posts
13 years ago
Luke Sturgeon's avatar Luke Sturgeon

HI Bhashkar,

Thanks, that’s exactly what I’ve implemented for now and it works fine. It just means if we add new status options in the future there’s a little more work because it relies on updating the conditions (on all relevant templates) and the CSS. It would be nice if I could just add the new status and my templates could automatically handle it.

I guess this is were a custom plugin or new feature could be requested. So that we could pass in the status and get all the properties from the DB.

For now the classes and CSS are the solution I’m going with.

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Hi Luke,

You are correct. As while creating the statuses from Control Panel, the color code is also being saved into DB. So a small plugin can be developed to fetch the color code.

But also, I think, it would be easy for you just write a query using the query module like:

{exp:query sql="SELECT highlight AS status_color FROM exp_statuses WHERE status='{status}' AND group_id='1'"}
{status_color}
{/exp:query}

Please Note: Within the query group_id can vary according to the status group assigned to that channel.

Here, {status_color} will give the color code of that status color.

I hope, it would help you.

Best Regards,

       
Luke Sturgeon's avatar
Luke Sturgeon
17 posts
13 years ago
Luke Sturgeon's avatar Luke Sturgeon

Great stuff. I always forget about the query module. Good idea thanks.

       
yzs's avatar
yzs
58 posts
one year ago
yzs's avatar yzs

can you please help with this:

<button [removed]SELECT highlight AS status_color FROM exp_statuses WHERE status=’{status}’”} {status_color} {/exp:query} ; border: none; mix-blend-mode: difference; padding: 10px; text-align: center; text-decoration: none; display: inline-block; font-size: 12px; font-weight: bold; font-variant-caps: petite-caps; margin: 4px 2px; border-radius: 30%;}”>{status}</button>

================================= what’s missing?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.