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.

Having problems with a conditional in related entries

October 23, 2011 1:52pm

Subscribe [4]
  • #16 / Oct 24, 2011 2:09pm

    Mike Mella

    178 posts

    This is the channel entries tag, which is the only thing I’m editing (I’m using Zoo Visitor to get some info about who’s posting if that matters, and the {pr-} variables are preload-replace variables):

    {exp:channel:entries channel="jobs" require_entry="yes"}       
           
           {exp:query sql="SELECT COUNT(*) as application_count FROM exp_channel_titles ct LEFT JOIN exp_relationships r ON r.rel_parent_id = ct.entry_id WHERE ct.author_id={logged_in_member_id} AND r.rel_child_id={entry_id}"}
             {if application_count > 0}
            <a href="#" class="disabled btn primary apply">You applied for this job</a>
             {if:else}
            <a href="http://{path=%27job/apply/{segment_2}%27}" class="btn primary apply">Apply for this job</a>
             {/if}
           {/exp:query}
           
           
          <a href="http://{path={pr-member-group}/company}">_       <div class="employer-logo">_       {!-- Get the logo of the company who posted this job: --}_        {exp:zoo_visitor:details username="{username}"}_         {exp:ce_img:single src="{visitor:cf-profiles-logo}" alt="{cf-profiles-company}" width="120"}_        {/exp:zoo_visitor:details}_       </div><!-- /#employer-logo -->_      </a>
    
          <div class="job-details">
           <h2>{title}</h2>
    <p>       <br />
            <a href="http://{path={pr-member-group}/company/{entry_id}}">{cf-jobs-company}</a> | {cf-jobs-location}</p>
    
    <p>              <br />
           {cf-jobs-summary}       <br />
          </div><!-- /.job-details --></p>
    
    <p>      {if no_results}<br />
           Please choose a job.<br />
          {/if}</p>
    
    <p>{/exp:channel:entries}

    Is that enough info?

  • #17 / Oct 24, 2011 2:20pm

    Wouter Vervloet

    758 posts

    Could you try putting a parse=‘inward’ parameter on the exp:query tag? Not sure, but I think the logged_in_member_id isn’t parsed before the query tag is run…

    {exp:query sql="..." parse='inward'}

    You could turn on the the profiler in the debug settings to see what actually is executed…

    — Wouter

  • #18 / Oct 24, 2011 4:04pm

    Mark Bowen

    12637 posts

    Just as a little bit of information, Wouter is correct in that {logged_in_member_id} probably won’t be available to the Query Module Tag as although it is a Global Variable they are one of the items that are parsed very late in a template. Module tags happen prior to this so you would probably need to use some PHP to get at the same information.

    Mark

  • #19 / Oct 24, 2011 4:16pm

    Mike Mella

    178 posts

    Parse=‘inward’ had no effect.

    I haven’t been able to get At The Gates’s solution to work either.  The channel entries tag doesn’t seem to recognize my custom fields when wrapped in the {exp:member:custom_profile_data} tag.

    Maybe I am better off using Playa then?  Playa would let me use the author= parameter?  It just seemed like overkill to solve this one issue.  On the other hand, I’m not crazy about using PHP and an SQL query in my templates.

  • #20 / Oct 24, 2011 4:17pm

    Wouter Vervloet

    758 posts

    As I suspected, the logged_in_member_x variable are parsed very late in the game, so I’m going to do something special for you 😉 Here’s an add-on from my personal collection (so it might not be foolproof), but it gets the job done for me.

    The extension is called “Omnipresence” and what it basically does is make all the session variables from the userdata array available as (early parsed) global variables and, as an added bonus, all the custom member fields as well.

    It’s as simple as {member:member_id} to output the member_id of the currently logged in member. There’s a huge list of variables available, but as I mentioned it’s one from my own personal collection, so there is no documentation available.

    Custom member vars ccan be accessed in the same way… {member:postcode} (if your member_field is called ‘postcode’)

    If you replace {logged_in_member_id} with {member:member_id} in the SQL query, you should be all set.

    — Wouter

  • #21 / Oct 24, 2011 4:28pm

    Mike Mella

    178 posts

    Thanks for this, Wouter.  After reading you post, I think I may have solved it:

    Zoo Member has a global variable call {zoo_member_id} that is parsed early like Omnipresence does.  I replaced {logged_in_member_id} with {zoo_member_id} and now your query seems to work.

    I’ll go with this solution for now.  Thanks again for all your help!

    - Mike

  • #22 / Oct 24, 2011 4:34pm

    Wouter Vervloet

    758 posts

    You’re welcome Mike 😊

  • #23 / Oct 25, 2011 2:09am

    ahmad saad

    364 posts

    glad I see u have the solution.

    and thanks Wouter for your extension it’s will be very usefull for resolve parssing order problem.

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

ExpressionEngine News!

#eecms, #events, #releases