ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dynamic menu

February 02, 2012 5:17am

Subscribe [1]
  • #1 / Feb 02, 2012 5:17am

    Mat

    11 posts

    Hi All,

    Been trying to make a dynamic menu with EE, but I need to be able to use status outside of the channel:entries tags but within it. this way I can do some if/else statements is there a way?
    any help will be great.

    {if segment_1 == 'guide' OR segment_1 == 'guide_view'}
                  <li class="active"><a href="http://{site_url}guide">Guide</a>
                    <ul>
                    
                      <ul>
                     {exp:channel:entries channel="guide"
                      {if segment_2 == 'place1'}
                        status="place1"
                      {/if}
                      {if segment_2 == 'place2'}
                        status="place2"
                      {/if}
                      {if segment_2 == 'place3'}
                        status="place3"
                      {/if}
                      {if segment_2 == 'place4'}
                        status="place4"
                      {/if}
                      {if segment_2 == 'place5'}
                        status="place5"
                      {/if}
                      {if segment_2 == 'place6'}
                        status="place6"
                      {/if}
                      {if segment_2 == 'place7'}
                        status="place7"
                      {/if}
                      {if segment_2 == 'place8'}
                        status="place8"
                      {/if}
                      {if segment_2 == 'place9'}
                        status="place9"
                      {/if}
                     sort="asc" dynamic="no" }
                     
                      <li>a href="{title_permalink='guide_view'}">{title}</a></li>
                    
                    {/exp:channel:entries}
                    </ul>
                    {if segment_2 != ''}
                    {exp:channel:entries channel="guide" sort="asc" dynamic="no"}
                     <li><a href="http://{title_permalink=guide_view}">{title}</a></li>
                    {/exp:channel:entries}
                    {/if}  
                    </ul>
                  </li>
  • #2 / Feb 03, 2012 2:34pm

    Kevin Smith

    4784 posts

    Hi Mat,

    To be honest, I’m not sure I quite understand what you’re trying to accomplish. Would you mind clearing it up for me? Maybe giving me an example?

    Looking at this code, though, I can see a few things. First, it looks like you’re leaving the first conditional unclosed. Second, this channel entries opening tag:

    {exp:channel:entries channel="guide"
                      {if segment_2 == 'place1'}
                        status="place1"
                      {/if}
                      {if segment_2 == 'place2'}
                        status="place2"
                      {/if}
                      {if segment_2 == 'place3'}
                        status="place3"
                      {/if}
                      {if segment_2 == 'place4'}
                        status="place4"
                      {/if}
                      {if segment_2 == 'place5'}
                        status="place5"
                      {/if}
                      {if segment_2 == 'place6'}
                        status="place6"
                      {/if}
                      {if segment_2 == 'place7'}
                        status="place7"
                      {/if}
                      {if segment_2 == 'place8'}
                        status="place8"
                      {/if}
                      {if segment_2 == 'place9'}
                        status="place9"
                      {/if}
                     sort="asc" dynamic="no" }

    ...could be a LOT simpler:

    {exp:channel:entries channel="guide" status="{segment_2}" sort="asc" dynamic="no">

    Could you give that one a try instead?

  • #3 / Feb 06, 2012 3:17am

    Mat

    11 posts

    Thank you for that, my code was way over bloated. What I am trying to achieve is a dynamic menu based on a status, but still maintain a parent item so that the structure will be something like this rendered:

    <ul>
        <li>Country
          <ul>
            <li>State</li>
          </ul>
        </li>
        <li>Example Menu Item</li>
    <ul>

    So currently the 1st part works fine but as soon as I select a state, the menu basically resets to before I have selected country, so it closes.

    Is this possible?

  • #4 / Feb 08, 2012 4:17pm

    Dan Decker

    7338 posts

    Hi Mat,

    I’m glad Kevin’s suggestion was able to simplify your code.

    In the example you provided, where are you getting the value for “Country”. Is that also a channel entries tag? A URL segment?

    Can you post the template code, with Kevin’s suggestions, here again so we can see the big picture? Any context about where you are getting the dynamic information and what your ultimate goal is would be excellent. Are you building a menu for navigation?

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases