I am creating a Custom List for a Frontend view of a CC connection. One of the fields in the connection is named 'staff_website'. This field (VARCHAR(150)) either contains a website URL, or the text "No Website". In the Frontend view, I would like my list to add a hyperlink if there is a URL in the field, but display "No Website" if there is not.
In the Custom List, I have the following to evaluate the value of 'staff_website':
However, this code merely returns the value of 'staff_website' for every row. If I use:
the code returns "None" for every row. I am missing something basic in here, but no matter what I try I cannot get it to work.
In the Custom List, I have the following to evaluate the value of 'staff_website':
<?php
$mysite = "{staff_website}";
if ($mysite == "No Website") {$showsite = "None";}
else {$showsite = "{staff_website}";}
echo $showsite;
?>
However, this code merely returns the value of 'staff_website' for every row. If I use:
<?php
$mysite = "{staff_website}";
if ($mysite = "No Website") {$showsite = "None";}
else {$showsite = "{staff_website}";}
echo $showsite;
?>
the code returns "None" for every row. I am missing something basic in here, but no matter what I try I cannot get it to work.
Hi Rick,
Can you mix and match curly brackets and PHP in this version of CC?? You couldn't with the old one.
Your second version is missing an = in $mysite = "No Website". As written the If clause will always be true.
Bob
Can you mix and match curly brackets and PHP in this version of CC?? You couldn't with the old one.
Your second version is missing an = in $mysite = "No Website". As written the If clause will always be true.
Bob
Bob,
I don't know if you can mix the curly brackets and PHP. My second one is missing another "=", but the first one has it and it doesn't work either.
How can I get the fields in PHP if I don't use curly brackets?
Rick
I don't know if you can mix the curly brackets and PHP. My second one is missing another "=", but the first one has it and it doesn't work either.
How can I get the fields in PHP if I don't use curly brackets?
Rick
Hi Rick,
I think this is what you need (not tested though):
Bob
I think this is what you need (not tested though):
<?php
if ( !isset($row['staff_website']) || !$row['staff_website'] ) {
$row['staff_website'] = 'No website';
}
echo $row['staff_website'];
?>
Bob
Thanks for the help, Bob. Unfortunately, it didn't work. Every row is returning 'No Website', even if there is a value in the 'staff_website' field. Is it because the field is VARCHAR?
Oops, found out why. I am using a ModelID on this connection, so I had to add that ID to each reference for that field. So it looks like this now:
I changed it a little, so that if there is no website defined it simply displays "None". If there is a website, it will display the site with a hyperlink.
Thanks for all your help with this!!!
Rick
<?php
if ( !isset($row['AllTeachers']['staff_website']) || !$row['AllTeachers']['staff_website'] ) {
$showsite = "None"; }
else { $showsite = "<a href='http://" . $row['AllTeachers']['staff_website'] . "' target='_blank'>VISIT SITE</a>"; }
echo $showsite;
?>
I changed it a little, so that if there is no website defined it simply displays "None". If there is a website, it will display the site with a hyperlink.
Thanks for all your help with this!!!
Rick
Never miss the Model ID!🙂
and you can try to debug the data using this function:
Regards,
Max
and you can try to debug the data using this function:
print_r2($row);
Regards,
Max
This topic is locked and no more replies can be posted.