How to have <div> added in <ul> category menu link list generated by CMSB generated

6 posts by 3 authors in: Forums > CMS Builder
Last Post: July 27, 2011   (RSS)

By davidcmsb - July 22, 2011 - edited: July 22, 2011

Hi,

I want to use the category menu list of links to categories that CMSB generates with a menu script. This menu script is a Dreamweaver extension that generates the <ul> list like this:

div id="p7TMM_1" class="p7TMM04">
81 <ul class="p7TMM">
82 <li><a href="#">Root Menu Item</a>
83 <div>
84 <ul>
85 <li><a href="#">Menu Item</a></li>
86 <li><a href="#">Menu Item</a></li>
87 <li><a href="#">Menu Item</a></li>
88 </ul>
89 </div>
90 </li>
91 <li><a href="#">Root Menu Item</a>
92 <div>
93 <ul>
94 <li><a href="#">Menu Item</a></li>
95 <li><a href="#">Menu Item</a>
96 <div>
97 <ul>
98 <li><a href="#">Menu Item</a></li>
99 <li><a href="#">Menu Item</a></li>
100 <li><a href="#">Menu Item</a></li>
101 </ul>
102 </div>
103 </li>
104 <li><a href="#">Sub-Menu Item</a></li>
105 <li><a href="#">Sub-Menu Item</a></li>
106 </ul>
107 </div>
108 </li>
109 <li><a href="#">Root Menu Item</a>
110 <div>
111 <ul>
112 <li><a href="04carbon.htm">Current Mark</a></li>
113 <li><a href="#">Menu Item</a></li>
114 <li><a href="#">Menu Item</a></li>
115 </ul>
116 </div>
117 </li>
118 <li><a href="#">Root Menu Item</a>
119 <div>
120 <ul>
121 <li><a href="#">Menu Item</a></li>
122 <li><a href="#">Menu Item</a></li>
123 <li><a href="#">Menu Item</a></li>
124 </ul>
125 </div>
126 </li>
127 </ul>
128 <!--[if lte IE 6]>
129<style>.p7TMM04 .p7TMM, .p7TMM04 a, .p7TMM04 li {height:1%;}</style>
130<![endif]-->
131 <!--[if IE 5]>
132<style>.p7TMM04 a, .p7TMM04 a {overflow: visible !important;}</style>
133<![endif]-->
134 <script type="text/javascript">
135<!--
136P7_TMMop('p7TMM_1',3,0,0,3,1,1,1,0,-1,150);
137//-->
138 </script>


As you can see, it wraps submenu <ul>'s in <div> tags (see, e.g., lines 83 & 89, 92 & 107, and 96 & 102, above).

I think I can add the first opening <div> by using the __hasChild function by using perhaps something like this which adds the div after the link if the category record has a child, for example this --

<ul>
<li><a href="?">(All Articles)</a></li>
<?php foreach ($categoriesRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_hasChild']): ?>
<a href="#"><?php echo $categoryRecord['name'] ?></a> <div>
<?php else: ?>
<?php if ($categoryRecord['_isSelected']): ?> <b> <?php endif ?>
<a href="?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?> </b> <?php endif ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach ?>
</ul>


BUT I just can't figure out after wrestling with it a long time just how to add the ending </div> tag. Something using _isLastChild perhaps, but I just can't figure out the exact code needed. And, it has to go after the </ul> tag that CMSB seems to auto generate to end the sub menu <ul>'s inside the main <ul>.

So, what I need is the code that will generate the category links in the format as per that used by the menu script I want to use as shown above that will add the necessary <div> and </div> surrounding the <ul></ul> pairs that get generated for sub menus (and sub sub menus etc.).

Thanks very much.

Re: [davidcmsb] How to have <div> added in <ul> category menu link list generated by CMSB generated

By Jason - July 22, 2011

Hi,

That's an interesting problem. I've looking into it and you can do it, but you can't use the _listItemStart and _listItemEnd pseudo fields.

What you can do is use the _hasChild and _isLastChild pseudo fields to manually create the <ul> and <li> tags. For example:

<div>
<ul>
<?php foreach ($categories as $category): ?>
<li><?php echo $category['name'];?>

<?php if ($category['_hasChild']): ?>
<div>
<ul>
<?php else: ?>
</li>
<?php endif ?>

<?php if ($category['_isLastChild'] && !$category['_hasChild']): ?>
</ul>
</div>
<?php endif ?>

<?php endforeach ?>
</ul>
</div>


Hope this helps get you started.
---------------------------------------------------
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: [davidcmsb] How to have <div> added in <ul> category menu link list generated by CMSB generated

By ross - July 25, 2011

Hi David

Thanks for posting :). I think the best thing to do here would be setup a sample template with an example menu hardcoded on it exactly how you want everything to display. Do you have that already? Can you attach a copy for me to work with?

From there, I'll also get you to send me a copy of the schema file for that section (you'll find it in /data/schema).

With all of this, I can create a local copy of what you are working on and it will be much easier for me to test out.

The alternative would be for me to guess some code and let you test it, then tweak from there.

Let me know what you think. 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] How to have <div> added in <ul> category menu link list generated by CMSB generated

By davidcmsb - July 25, 2011

Thanks Ross. Let's for now do the second thing you said, i.e., give me some code you think will work and I'll test it and let you know the results. You should probably be able to give me some code that will create the unordered list structure that needs to work for this.

Thanks,
David

Re: [davidcmsb] How to have <div> added in <ul> category menu link list generated by CMSB generated

By Jason - July 27, 2011

Hi David,

_isLastChild indicates if it's the last child in a given branch. So we only want to close off a </ul> if it's the last child and has no children itself.

We can try also closing the </li> tag when closing a <ul> like this:



<div>
<ul>
<?php foreach ($categoriesRecords as $categoryRecord): ?>
<li><?php echo $categoryRecord['name'];?>

<?php if ($categoryRecord['_hasChild']): ?>
<div>
<ul>
<?php else: ?>
</li>
<?php endif ?>

<?php if ($categoryRecord['_isLastChild'] && !$categoryRecord['_hasChild']): ?>
</li>
</ul>
</div>
<?php endif ?>

<?php endforeach ?>
</ul>
</div>


Give this a try and let us know if this works for you.

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/