fresher
fresher

Reputation: 911

Display the text only if attribute value = "yes" in magneto site

we have custom dropdown attribute with values : "YES" or "NO" in backend.

I want to display the text in view page only if value = "yes"

attribute code : name_order . below is code.

<?php echo "display text"; ?>

Upvotes: 0

Views: 2883

Answers (3)

David Wilkinson
David Wilkinson

Reputation: 5118

I'm assuming it's a product attribute?

If so, you can get value of your attribute per product by using the getAttributeText() method.

<?php
    if($_product->getAttributeText("name_order") == "Yes") {
        echo "Set to Yes";
    } else {
        echo "Set to No";
    }
?>

Upvotes: 1

codedge
codedge

Reputation: 5174

I assume you mean the template app/design/frontend/default/<YOUR THEME>/template/catalog/product/view.phtml and you implemented the attribute correctly you can access it via

$_product->getNameOrder()

Upvotes: 1

Laty
Laty

Reputation: 191

Go Admin -> Catalog -> Attributes -> Manage Attributes

Set "Used in Product View page" to Yes

Then in view.phtml :

if($_product->getAttributeText('name_order')=='yes')
{
    echo "display text";
}

Upvotes: 1

Related Questions