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.

Making dynamic submenus >> Embedded Templates?

June 12, 2012 9:34pm

Subscribe [3]
  • #1 / Jun 12, 2012 9:34pm

    calendarfm

    7 posts

    Build v2.4.0. I have a website that goes a few levels deep: home/projects/details/detailed_project_page.

    I’d like to put a sub-menu of items in the various detailed_project_pages. The sub-menu will be different for every page. I imagine the best way would be to create a channel to feed the various sub-menus, and use an embedded template in the detailed_product_pages to display a dynamic menu. This is basic EE functionality, but I can’t get it to work. I have read the documentation for embedding templates.

    Here is my details page:

    {embed="embeds/html_header" my_page_title="Project Detail {exp:channel:entries channel="projects" disable="member_data|trackbacks|pagination" limit="1"} | {title}{/exp:channel:entries}"}
    {embed="embeds/page_header" the_url_title="projects" my_location="projects"} 
    {embed="embeds/small_header" my_page_title="Projects"} 
    
      <div class="body">
        <div class="left">
    
    {embed="embeds/detail_sidenav" the_url_title="ami_details"}    
    {snp_sidequote}
        <div class="big_center no_margin">
         {exp:channel:entries channel="projects" disable="categories|member_data|pagination" sort="asc" limit="1"} 
      <h2>{title}</h2>
    <p> {subtitle}<br />
     {index_image}{page_body}<br />
          {/exp:channel:entries}<br />
        </div><br />
        <div class="clr"></div><br />
      </div><br />
    </div><br />
    </div>

    Here is my embedded template:

    <div class="box no_margin">
            <div class="box_t">
              <div class="box_b">
                <h2>Sub Navigation</h2>
    <p>            <ul><br />
     {exp:channel:entries channel="ami_details" disable="categories|member_data|pagination" url_title="{embed:the_url_title}"}<br />
                  <li><a href="http://{url_title_path=%27projects/detail%27}" class="active">{title}</a></li><br />
     {/exp:channel:entries}<br />
                </ul><br />
              </div><br />
            </div><br />
          </div>

    The channel I’m using to store data to pass into the navigation menu is called “ami_details.” Can I use the same channel to contain all information for the various submenus I want to display? Is this the best way of creating sub-navigation on pages that are already a few levels deep? If not, what would work better? What am I doing wrong, if this is the best way to handle the task?

     

  • #2 / Jun 13, 2012 5:14pm

    Dan Decker

    7338 posts

    Hi calendarfm,

    Thanks for asking your question and welcome to the Forums!

    What you need to do is add the dynamic=“no” parameter to your embedded template, like so:

    {exp:channel:entries channel="ami_details" disable="categories|member_data|pagination" url_title="{embed:the_url_title}" dynamic="no"}
                  <li><a href="http://{url_title_path=%27projects/detail%27}" class="active">{title}</a></li>
     {/exp:channel:entries}

    That tells channel entries to ignore information in the URL and behave exactly like you tell it to.

    Let me know if that isn’t it.

    Cheers,

  • #3 / Jun 13, 2012 6:32pm

    calendarfm

    7 posts

    Dan,

    Thanks very much for your reply. This did not fix the problem, I’m still seeing an empty menu. Is this a normal application of embedded templates in EE? Ideally, I would be able to put my menu items in the same channel as the other “projects” content, but I’m not sure how to do this, since that would require adding several instances of the same field. So I figured the logical thing to do is set up a separate channel for menu items. One idea i had is to categorize menu items in this channel and, by passing a category tag to the embedded template, display the correct menu for each page. This is not represented in the code above, but might offer a clue as to what I am trying to achieve.

    Thanks again for your input!

    Justin

  • #4 / Jun 15, 2012 12:31am

    calendarfm

    7 posts

    For anyone reading this post, I’m creating this website for a client, and time is of the essence. Can anyone tell me a way to improve this post so it will invite helpful responses? I’m not getting many bites…

  • #5 / Jun 15, 2012 8:51am

    MID

    166 posts

    {embed="embeds/detail_sidenav" the_url_title="ami_details"}

    What is ami_details? Should it be {ami_details}? And inside an entries pair?

  • #6 / Jun 15, 2012 3:40pm

    Dan Decker

    7338 posts

    Hi calendarfm,

    I empathize with your frustration, I really do.

    You’ve got several things going on here that are complex to follow. In your first set of examples, you haver 2 embed calls, calling different templates but using the same embed variable “the_url_title”

    That may be part of the issue. You should space those to be completely different to avoid conflicts.

    As Zach points out, you have this:

    {embed="embeds/detail_sidenav" the_url_title="ami_details"}

    Which is then called as the url_title parameter in the embedded template. Is there an entry in the ami_details channel that has a url_title of “ami_details” as well?

    Here are a couple of other options to investigate. Using categories, a free tutorial on Train:ee.

    Take a look at Structure. It can help you build automatic navigation and control your URLs. Also, NavEE is built just for navigation.

    Cheers,

  • #7 / Jun 15, 2012 3:58pm

    calendarfm

    7 posts

    Thanks for both of your responses. I’ll go back to the drawing board and try to learn the basics better.

  • #8 / Jun 15, 2012 9:41pm

    calendarfm

    7 posts

    For further clarification on what I’m attempting to do, I’ve put the page onto a production server here: http://m8ker.com/projects.

    I’m trying to make a unique menu on pages one level deeper, on the detail pages:  http://m8ker.com/projects/detail/arts-math-integration-project.

    Any advice on how to do this would be very helpful. Thanks!

  • #9 / Jun 18, 2012 1:31am

    narration

    773 posts

    calendarfm, I think it will help if you consider structurally what you are trying to accomplish.

    - a unique submenu needs to be accessible for each page
    - each submenu itself has multiple entries, which you will no doubt want to set in an order.

    You can see this is a list of lists. A channel in EE is a simple list. It would be possible to put your multiple display entries within each submenu’s channel entry, by using custom fields, but better using something flexible like the Matrix add-on. You don’t need an embed to include this sub-menu, if you think about it, and that knowledge will help you simplify, regardless of method you use.

    Once you see this pattern (draw it in one or more ways and that will help), then you will see also the value of add-ons which take care of the needs automatically for you, which are specialized to menus, and thus give you flexibility while saving a lot of time.

    You’ve had two good suggestions, and of them NavEE is specifically provided to create menus, without otherwise forcing anything about site design. You can see from the recommendations that it has a lot of sucess behind it.

    The Structure alternative goes much farther. It takes over ExpressionEngine’s operation internally so as to provide a visual structure for people creating pages on your site, also providing menu content to match the site structure. This has a lot of consequences, so you’d want to be sure it was an advantage for you, which in turn, possibly it might be at some point. Structure is very actively maintained, which it apparently needs to be in order to match changes in EE releases, which is another consideration.

    There are other possibilities, but I don’t want to make this any more complicated, since you’re under pressure and at a stage with EE.

    Given what you’ve said, a suggestion would probably be to go with NavEE at this time. Getting it to do what you want should be quite straightforward and worth the effort, to get an initial example up. Then you will have a framework that’s easy to work with as you go forward with your customer.

    Hoping this turns out to be useful and good advice.

    Regards,
    Clive

  • #10 / Jun 18, 2012 3:10pm

    calendarfm

    7 posts

    Thanks, Clive, for breaking it down like that, that really helps. I’ll give NavEE a go, as also suggested by Dan. Another recommendation I got from Michael Boyink was to check out Static Content posts on TrainEE

  • #11 / Jun 20, 2012 3:33pm

    calendarfm

    7 posts

    For anyone interested in my solution to this issue, I have used the Matrix plugin to hold all content for that channel within the channel, which I am hiding in collapsible divs via Bootstrap.

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

ExpressionEngine News!

#eecms, #events, #releases