1

I have a content type called specials

In that content type I have a field called discount code which has a machine name of field_discount_code

I have a custom node template called node--specials.tpl.php that I am using to fomate the display of this content type

If the discount code if filled in by the user I want drupal to show some text if it is left empty I want it show some other generic text

here is the code I am trying but not having any luck with

<?php if (!empty($content['field_discount_code'])): ?>

<p>Call <strong>1-800-661-2555</strong> to contact our Guest Service specialists to reserve this package or book online by using discount code "<strong><?php print render($content['field_discount_code']);?></strong>".</p>

<?php else: ?>

<p>Call <strong>1-800-661-2555</strong> to contact our Guest Service specialists to reserve this package.</p>

<?php endif; ?>

If I leave the discount code empty drupal is still showing the first text chunk but with nothing in the render($content['field_discount_code']); area.

so like this

Call 1-800-661-2555 to contact our Guest Service specialists to reserve this package or book online by using discount code "".

I have also tried

<?php if ($content['field_discount_code'] == "NONE"): ?>

text to display here

<?php else: ?>

text to display here

<?php endif; ?> 

but no joy I am relatively new to drupal dev so perhaps I am doing this the wrong way any insight would be greatly appreciated!

0

That's weird, the first code works in my end. Are you sure the node--specials.tpl.php is being called in the first place? I am suspecting that maybe you're still using node.tpl.php though I'm not sure.

Try to print some text in your tpl file to check if it is being used by your content type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.