Well, here’s my analysis. First, the ClientsAndProjectsPage_Template code:
{!-- First use the Fresh Variables module to define two variables:
current_category = {exp:weblog:entries limit='1'}{categories}{category_id}{/categories}{/exp:weblog:entries}
current_entry= {exp:weblog:entries limit='1'}{entry_id}{/exp:weblog:entries}
Then embed the two menus inside the main template with these lines:
--}
Current Category {current_category} {!-- This used just for testing purposes --}
{embed="template_group/_embedded_clients_menu_template" my_cat="{current_category}"}
{embed="template_group/_embedded_projects_menu_template" my_cat="{current_category}" my_entry="{current_entry}"}
{!-- The following displays an entry's content resulting from selecting a "project" entry --}
{exp:weblog:entries weblog="weblog" limit="1"}
{summary}
{body}
{/exp:weblog:entries}
What is most interesting here is how the Fresh Variables we’ve created “deliver” just what is needed—the current_category and current_entry—completely externally from the template per se, yet in response to what is called upon by the links and resulting from their own contribution. It is a recursive seeming thing. Fresh Variables must parse VERY early!
Then the “client” code, placed into a template we have called _embedded_clients_menu_template:
(I use underscores instead of periods to indicate a hidden template in my config.php file, because some server hosts do not allow uploading “traditionally” hidden files starting with periods. Yahoo is one such host.)
<div id="clients_menu">
<h1>Clients Menu</h1>
<ul>
{exp:weblog:categories weblog="weblog" style="linear" show_empty="no" category_group="1"}
{if segment_3 == "C{category_id}" OR "{embed:my_cat}" == "{category_id}" }
<li class="nav_active">{category_name}</li>
{if:else}
<li><a href="{path=template_group/ClientsAndProjectsPage_Template}">{category_name}</a></li>
{/if}
{/exp:weblog:categories}
</ul>
<!-- close clients_menu --></div>
I used show_empty="no" to eliminate any empty categories, which muck things up here. category_group="1" is included to narrow down what group is displayed, and could display other groups with digits separated by pipes: category_group="1|4" for instance.
Then the project code, which we have called _embedded_projects_menu_template:
<div id="projects_menu">
<h1>Projects Menu</h1>
<ul>
{exp:weblog:entries weblog="weblog" category="{embed:my_cat}" dynamic="off" sort="desc"}
{if (segment_3 == "{entry_id}") OR ("{embed:my_entry}" == "{entry_id}") }
<li class="subnav_active">{title}</li>
{if:else}
<li><a href="{permalink="template_group/ClientsAndProjectsPage_Template"}">{title}</a></li>
{/if}
{/exp:weblog:entries}
</ul>
<!-- close projects_menu --></div>
I did find that our Fresh Variables were definitely grabbing the most recent entry to the weblog to get its category_id and entry_id information initially upon page load (that is, when no category/segment_3 or entry/segment_3 exist in the URL). Also, once an entry is selected from among the “projects” listing, the entry id makes implicit the category id, and that info is being fed to our Fresh Variable ({current_category} which becomes my_cat). That’s why the test for my_entry and my_cat are always needed, especially after entries are selected, to keep the category info up to date (in our _embedded_clients_menu_template).
I had to make an entry “sticky” in the edit page (in Options) in order to force a desired particular entry and its associated category to be the top one, so that the topmost link being displayed was also the one showing as already selected and current. I wonder if there is another way in our scenario to get the Fresh Variables we used to receive some other default initial setting? Does a mess occur if an entry has multiple categories assigned to it? Probably it takes the lowest numbered one… need to test that, or simply avoid that situation!
After we start actually clicking on “client” links, though, EE reads from the URL and acts just like dynamic is turned on! This indicates that our permalinks and path= statements are working right (always dynamically, generated from the database), and that our test for segment_3 is functioning like it should be, reading from the URL to determine if the dynamically generated listing is also the current listing, while keeping categories in entries in our awareness through the my_cat test, so the “client” (actually the category) continues to be shown as the active one when the url is showing an entry_id now instead of a category_id in segment_3.
Much of what is going on is what dynamic="on" makes happen in a typical situation behind the scenes, but we are performing that test explicitly, and manually, returning the same results while keeping things under our control so that the “clients” list stays constant irrespective of the URL, yet the “projects” list changes based upon “client” selected, and the links show their “current link” status.
I still say that this is elegant enough to merit a Wiki entry. Maybe somebody will drop by and clear up any errors in my analysis here.
Terry