Custom Attribute if nothing is entered show CollectionName

Permalink
Hello,

I have set up a custom attribute to sit inside my <h1> if nothing if displayed I want to just have the default page title. I can do this with an if/else statement I expect but not too sure how to go about it.

Code for my attribute
<h1><?php echo $c->getCollectionAttributeValue('heading_1') ?></h1>


Now I want to add if nothing entered here use
<?php echo $c->getCollectionName() ?>

sarah3585
 
ScottC replied on at Permalink Best Answer Reply
ScottC
Hi Sarah,
$echod = $c->getCollectionAttributeValue('heading_1');
if(!echod || !strlen($echod){
$echod = $c->getCollectionName();
print $echod;
}


That's the easiest way.
sarah3585 replied on at Permalink Reply
sarah3585
Hi Scott,

Thanks so much for that. There was a syntax error and after fixing it I still can't get it to work.
[code]
$echod = $c->getCollectionAttributeValue('heading_1');
if(!echod || !strlen($echod)){
$echod = $c->getCollectionName();
print $echod;
}
[code]
ScottC replied on at Permalink Reply
ScottC
sorry about that, yeah i left off a ")" :)

I'm glad I could help.
sarah3585 replied on at Permalink Reply
sarah3585
The code isn't outputting anything, sorry if i wasn't clear in my previous post that it wasn't working after the syntax fix.