Jump to content

output a style in an echo


kaz
 Share

Recommended Posts

A client would like to have a checkbox or similar for an image field in order to apply a style.

echo "
<img class='{$page->check}' src='{$page->image->url}'>";

I have thought about creating a checkbox, but it's not so easy because the class must given out in an echo.

How to pass a class, a style in an echo?

Link to comment
Share on other sites

@kaz you could store your class in a variable before echo
 

// storing class in a variable
$class = ($page->check == 1) ? "checkedClass" : "defaultClass";
//
// or emtpy by default
// $class = ($page->check == 1) ) "checkedClass" : "";

echo "<img class='$class' src='{$page->image->url}'>";

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...