Display/hide link

15 posts by 5 authors in: Forums > CMS Builder
Last Post: July 22, 2009   (RSS)

By fleff - July 17, 2009

My client wants to be able to display a link on his home page to another page only under certain circumstances. Otherwise no visible link. I've set up a page in CMS Builder that can have either some text or no text at all and tried to trigger the visibility of the link on the home page only if the client enters some text on the blank page. A JavaScript then checks to see if the page is blank and if not, displays the link on the home page. The script is:

<div class="text_11_vb_red">
<script type="text/javascript">
if ('http://xxxx.org/emergency_linkDetail.php')
{
document.write('<a href="http://xxxx.org/emergency_infoDetail.php" class="navlinks_emergency">Emergency Information</a>');
}
</script>
</div>

I tried this JavaScript in one of my Listings Manager websites and it worked fine using a listings field ($lfield52$) in the "if" statement to see if it was empty. But I can't figure out how to get it to check the content of the emergency_linkDetail.php page to see if it is empty -- or if it has a keyword on it that will trigger the link. If LM were still available, I would have done it there. But don't get me wrong, I think CMS Builder is great.

Maybe there's a better way to accomplish this. Any help would be much appreciated.

Thanks,

Farnham

Re: [fleff] Display/hide link

By fleff - July 18, 2009

I've also tried this:

<script type="text/javascript">
if ('$link_creatorRecord["emergency_link"]' == 'yes')
{
document.write('<a href="http://xxxx.org/emergency_infoDetail.php" class="navlinks_emergency">Emergency Information</a>');
}
</script>

Farnham

Re: [fleff] Display/hide link

By isdoo - July 19, 2009

if you are checking a field in a table to see if it is populated then, you would normally use something like...

<?php if($newsRecord['field']): ?>
Action
<?php else: ?>
<?php endif ?>

So perhaps

<?php if($link_creatorRecord['emergency_link']): ?>
<script type="text/javascript">
{
document.write('<a href="http://xxxx.org/emergency_infoDetail.php" class="navlinks_emergency">Emergency Information</a>');
}
</script>
<?php else: ?>
<?php endif ?>

Re: [fleff] Display/hide link

By isdoo - July 20, 2009

Your client could put anything in the field link_creatorRecord['emergency_link'] and then simply blank the field out, with nothing in it to hide the link.

Re: [isdoo] Display/hide link

By fleff - July 20, 2009

I know what you mean, isdoo. It's what I had in mind when setting it up, but it isn't working. It puts the link on the page just fine when there is some text in the $link_creatorRecord field, but the link stays on the home page when I empty the field. That's why I was wondering about an "else" statement that would remove the link. Or maybe there is something else I could do to get it to work. Thanks for your help,
Farnham

Re: [fleff] Display/hide link

By Kenny - July 20, 2009 - edited: July 20, 2009

Forget the javascript all together

Just write a regular if statement that is triggered when the text field contains content

REGULAR IF STATEMENT

<?php if ($link_creatorRecord['emergency_link']): ?>
***Insert other code here***
<?php endif ?>

or optionally you can write an if statement that is triggered when the field is blank

REGULAR IF DOES NOT EXIST STATEMENT

<?php if (!$link_creatorRecord['emergency_link']): ?>
***Insert other code here***
<?php endif ?>


Kenny

Re: [fleff] Display/hide link

By ross - July 21, 2009

Hi Farnham

I agree with sagentic. Let's get you switched over to a fully PHP solution so that we can eliminate the JavaScript as a possible problem.

Can you give that a shot? And then perhaps post a copy of your whole template (as an attachment, please :)) so we can take a closer look at how it's all put together.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Display/hide link

By fleff - July 21, 2009

Hi Ross,

Thanks for the response. My guess is that either isdoo's or sagentic's script will work and that I'm doing something wrong. My emergency_linkDetail.php file works fine and either has a word on the page or nothing on the page when I enter or delete in the CMSB Link Creator section. But it posts the link on the website home page (copy attached) whether the page has a word or not, and then the link won't go away if I empty the emergency_linkDetail.php page. Do I have a path wrong somewhere or what? I'm sure it will do what I want once you take a look at it. Btw, the ticket ID is SJI-489756.

Best regards, Farnham

Re: [fleff] Display/hide link

By zip222 - July 21, 2009

I think the problem is because your file is .htm rather than .php
Its likely that its not executing the php commands. Try switching the extension to .php and see if it works.