Silly(?) Question re: conditional lists
5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 9, 2010 (RSS)
I'm creating a Spanish-language version of a site for a client, and have created fields where the translated content goes ("title_SP", "content_sp", "uploads_sp", etc.). I also created a mechanism to set cookies based on language preference, etc. and have all that working.
My main question pertains to the menus - I'm using nested-list drop-down menus (jquery) that get auto-generated by creating a list viewer for each category. Since the client does not want to translate each and every page of the site into Spanish, they only want the pages that *are* in Spanish to appear on the top nav. Other than hand-coding a custom menu list, is there a way to check if a field (such as "name_sp") exists for each record within a category, and only spit out a list with the results that do?
I've looked through the forum and my CMSB cookbook, and can't seem to find an answer... it seems like it should be simple, but I'm stuck. Thanks in advance for your help!
-Dan
P.S. Below is the code I'm using to generate the category lists. I'd like it to only produce results for records where there is actual data existing for "name_sp":
<?php
list($about_usRecords, $selectedTestRecord) = getCategories(array(
'tableName' => 'about_us',
));
?>
<?php foreach ($about_usRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?><b><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name_sp'] ?></a></b>
<?php else: ?><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name_sp'] ?></a>
<?php endif; ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>
Re: [danwilson] Silly(?) Question re: conditional lists
By Jason - November 8, 2010
What you can do is use an if statement at the beginning of your foreach loop to check to see if there's a value for name_sp like this:
<?php foreach ($about_usRecords as $categoryRecord): ?>
<?php if($categoryRecord['name_sp']): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?><b><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name_sp'] ?></a></b>
<?php else: ?><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name_sp'] ?></a>
<?php endif; ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endif ?>
<?php endforeach; ?>
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Silly(?) Question re: conditional lists
I'm getting better at if/then/else logic, but that one had me vexed...
This is going to help me create some really elegant solutions for multi-lingual sites!
-Dan
Re: [danwilson] Silly(?) Question re: conditional lists
By danwilson - November 9, 2010 - edited: November 9, 2010
www.calloan916.com (A Sacramento, CA pawn shop) and
www.carequityloans.com (their sister site for title loans)
I use cookies to set the language preference, and CMSB to send the right contents. Works like a champ, and now I can offer this type of solution to anyone!
Thanks again, Jason!
Re: [danwilson] Silly(?) Question re: conditional lists
By Jason - November 9, 2010
No problem. I'm glad to hear that everything is working well.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/