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.

Reverse_Related_Entries Conditional Question

March 26, 2008 11:39pm

Subscribe [2]
  • #1 / Mar 26, 2008 11:39pm

    Joey Trimmer

    128 posts

    I’m afraid I’m totally confusing myself with this reverse_related_entries issue I’m having so I’ll try and explain simply!

    I have two weblogs, “our_work” (portfolio template) and “project” (project template). “project” is related to “our_work”.

    Here’s a template for example. In the right sidebar you see the “our_work” entries are the main sections and the sub-sections are the projects. Everything is working nicely here.

    The problem occurs when clicking on one of the projects, like this. I’m not sure how to only show the reverse_related_entries underneath it’s related weblog. I can either get it to show all related entries for EVERY “our_work” entry or no entries.

    I can’t figure out a proper conditional for this particular situation! Any help is much appreciated!

    My sidebar template, which looks perfect on the Portfolio page but not Project page, looks like this.

    <!--begin #right_sidebar-->
      <div id="right_sidebar">
        {exp:weblog:entries weblog="our_work" dynamic="off" disable="{disabled}"}
        <ul>
          <li><h3><a href="http://{url_title_path=how/portfolio}class=on">{title}</a></h3>
    <p>        {if segment_3 == url_title}<br />
            {reverse_related_entries sort="asc"}<br />
              <ul><br />
                <li><a href="http://{url_title_path=how/project}class=on">- {title}</a></li><br />
              </ul><br />
            {/reverse_related_entries}<br />
            {if:else}<br />
            {/if}<br />
          </li><br />
        </ul><br />
        {/exp:weblog:entries}<br />
      </div><!--/end #right_sidebar-->

    I know that the “{if segment_3 == url_title}” won’t work for the project page as it does the portfolio page. But I can’t figure out how to check what weblog the project relates to as there is no identifier in the URL.

  • #2 / Mar 27, 2008 10:45am

    Robin Sowell

    13255 posts

    OK- that right nav?  Should it look the same on the two example pages?  I’m a wee bit fuzzy on what you’re going for.

  • #3 / Mar 27, 2008 10:51am

    Joey Trimmer

    128 posts

    Hi Robin, thanks for taking a look! sorry, it’s a little hard to explain this one. But yes for the most part you are right.

    For example, when viewing the “Parent Project Muscular Dystrophy” page we should see only the related entries underneath it, as it does currently. Then, when viewing any of the related entries underneath it, such as Brand Position and Identity, since this is still part of “Parent Project” we should see the rest of the related entries under this section (and only this section).

    The problem is, if I use the above code it won’t list any because it’s pulling from the URL title of the “our_work” weblog. If I take the url_title conditional out of the above code it lists every related entry under each section. Meaning, all the sub nav shows regardless of which “our_work” section you are viewing.

    phew…hope that’s not TOO confusing.

  • #4 / Mar 27, 2008 11:07am

    Robin Sowell

    13255 posts

    OK- IF I get it, I think you need to sort of do it two different ways, depending on whether it’s a portfolio or a project template.  The part that borks on a project template is:

    {if segment_3 == url_title}

    Right?  So if that worked, all would be well?  IF that’s the case, you’d need to get the parent’s url_title on the project pages and use that instead of segment_3.  Would that work logic wise? 

    And- I think I’m going to shift to ‘how to’ because it’s more ‘brainstorm’ than standard ‘how does it work’.  But yea- IF using different conditionals on the two pages solves the problem, we can manage that.  Try hard coding one first to see if it does.

    Make sense?

  • #5 / Mar 27, 2008 11:18am

    Joey Trimmer

    128 posts

    Yes that does make sense. I’ve created a separate template to experiment with different conditionals for the project page but didn’t know how to grab the parent’s url_title like you mentioned. Sounds like a great idea.

    Here’s the project page with the different template. As you can see it expands on every section now.

  • #6 / Mar 27, 2008 11:24am

    Joey Trimmer

    128 posts

    Sorry, meant to include the new template code. Here’s what I’ve got minus any conditionals for the project page sidebar:

    <!--begin #right_sidebar-->
      <div id="right_sidebar">
        {exp:weblog:entries weblog="our_work" dynamic="off" disable="{disabled}"}
        <ul>
          <li><h3><a href="http://{url_title_path=how/portfolio}class=on">{title}</a></h3>
    <p>          <ul><br />
                {reverse_related_entries sort="asc"}<br />
                <li><a href="http://{url_title_path=how/project}class=on">- {title}</a></li><br />
                {/reverse_related_entries}<br />
              </ul><br />
          </li><br />
        </ul><br />
        {/exp:weblog:entries}<br />
      </div><!--/end #right_sidebar-->

  • #7 / Mar 27, 2008 1:06pm

    Joey Trimmer

    128 posts

    Since we’re on the related entry topic…I found a related problem (har har).

    I’m usin the next and prev tags for the project weblog. But they are only supposed to cycle within their related section. Instead, as it’s supposed to do, it cycles through every entry in the project weblog. For example: On this project entry, this is supposed to be the last. It shouldn’t have a next entry, only a previous back to “2005 Annual Report”. But instead it jumps over to another section.

    Today is gonna be a trying day I can feel it 😊

  • #8 / Mar 27, 2008 1:23pm

    Robin Sowell

    13255 posts

    Hee- yea.  Hm- ok, let’s ignore next/prev for the moment.  For the conditional- ok, here’s where it’s a pain.  It would be easy to get the parent url title inside the weblog tag used to show the project details.  The problem is getting that out to the navigation.  You can’t use a dynamic global due to parse order.  You can’t use a php variable due to parse order- needs to parse on output to define the php variable, but on input to stick it in the navigation weblog tag.

    So- could either use php parsed on input- do a query in php to figure out the parent url title- set the php variable- echo it out in the nav.  OR- could parse on output- set a php variable inside the project weblog tag.  EMBED the left nav and pass that php variable as an embed variable.  It could then be used in the embedded template where your nav is.  A little messier- but easier than the pure php approach.

    Er- did that make a lick of sense?

  • #9 / Mar 27, 2008 4:27pm

    Joey Trimmer

    128 posts

    Hey Robin, this makes sense and it’s a creative solution!

    I’m having a little trouble executing it exactly though. I liked your php output idea, it seemed to make the most sense. Do I need set both templates “project” and “nav_project” to php output specifically?

    I echoed a “Hello World” in the nav_project sidebar template and it’s posting it under each section again. So I’m doing something wrong.

  • #10 / Mar 27, 2008 5:20pm

    Joey Trimmer

    128 posts

    Ohhhh I missed the part where you said EMBED the variable! I’m new to embedding variables, this is fun! But still a little lost. So if my php variable in the “project” template is $related, in my embedded template how would I need to establish the embedded variable?

    {embed:related}

    THEN:

    {if embed:related != ""}

    I tried using just the {if embed:related != ""} with no luck. It doesn’t show any of the related fields.

  • #11 / Mar 27, 2008 6:19pm

    Joey Trimmer

    128 posts

    Hi again Robin. I started thinking about this deeper and I got super confused, though that’s not difficult to do today. I actually don’t see how your php strategy will work but I’d love to be wrong.

    Since the problem is that I can’t show the sub navigation of project entries that only relate to their “our_work” main section…shouldn’t the variable somehow be passed from the “our_work” weblog? Or maybe I’m not thinking of a proper conditional still.

    My thought was, within the project template and project weblog entries tag I call the related_entries and define the php variable there. THEN that passes to the embedded sidebar.

    I think my head just exploded. Too much coffee and I need to hit the gym then come back to the problem!

  • #12 / Mar 27, 2008 6:22pm

    Robin Sowell

    13255 posts

    OK- break it down and do one part first.  Ignore the php- just hard code an embed variable.  So if you put the whole nav in a template called ‘project_nav’- pass it like

    {embed="site/project_nave" parent_url="some_title"}

    Modify as needed.  Note- we’re ignoring the whole php issue right now- so just hard code in a url that will work.  Does it work doing it that way?  And if not- post the code you’re using in the embedded template- let’s take a look at your conditionals.

  • #13 / Mar 27, 2008 6:31pm

    Joey Trimmer

    128 posts

    Okay, yes, simple is better. So, ignoring all the php and just embedding the variable it didn’t work unfortunately. Here is how I’m doing it. In the project template I’m embedding like this:

    {embed="sidebars/nav_project" parent_url="related"}

    my nav_project template is as follows:

    <!--begin #right_sidebar-->
      <div id="right_sidebar">
        {exp:weblog:entries weblog="our_work" dynamic="off" disable="{disabled}"}
        <ul>
          <li><h3><a href="http://{url_title_path=how/portfolio}class=on">{title}</a></h3>
    <p>          <ul><br />
                {if embed:related != ""}<br />
                {reverse_related_entries sort="asc"}<br />
                <li><a href="http://{url_title_path=how/project}class=on">- {title}</a></li><br />
                {/reverse_related_entries}<br />
                {/if}<br />
              </ul><br />
          </li><br />
        </ul><br />
        {/exp:weblog:entries}<br />
      </div><!--/end #right_sidebar-->

    It still shows all related fields for all sections link

  • #14 / Mar 27, 2008 6:37pm

    Robin Sowell

    13255 posts

    OK- we’re trying to mimic:

    {if segment_3 == url_title}

    Right?  And- the embed is always going to have something in it.  So- try something like

    {if embed:related == url_title}

    Any luck- or am off on what we’re shooting for.

  • #15 / Mar 27, 2008 9:29pm

    Joey Trimmer

    128 posts

    yeah that’s what we’re going for…the problem I think is that we’re grabbing it from the wrong weblog if I’m not mistaken.

    In order to know which reverse_related_entries to display we need to know which related_entry they belong to right?

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

ExpressionEngine News!

#eecms, #events, #releases