0

I'm passing a variable into an embed file. I can output the value of the variable inside the embedded template no problem but when I use it in an channel:entries loop I'm not getting a result. Hard coding a value returns a result. Any thoughts?

<p>Member ID {embed:member_id}</p>
<?php $skills = array() ; ?>
{exp:channel:entries 
    channel="logbook"
    orderby="date"
    sort="desc"
    dynamic="no"
    author_id="{embed:member_id}"
    disable="categories|category_fields|member_data|pagination"
}
    <?php $skills[] = array('skill' => "{log_skill}{url_title}{/log_skill}", 'badge' => "{log_skill}{skill_badge}{/log_skill}"); ?>
    {/exp:channel:entries}

<script>
    var skills = <?php  echo json_encode($skills); ?>
</script>
2
  • Is the php parsing stage set to output? – Sobral Jul 30 '14 at 2:28
  • 1
    Try first removing all your PHP and just outputting the entries normally. – Derek Hogue Jul 30 '14 at 12:18
1

I have a sneaky suspicion that the previous page you are embeding from is using something like this:

{embed="foo/bar" member_id="{member_id}"}

{member_id} is a standard global var and does not get parsed until after your embed. So essentially what that embed code does is this:

<p>Member ID {member_id}</p> {!-- {embed:member_id} is replaced with {member_id} tag--}
<?php $skills = array() ; ?>
{exp:channel:entries 
    channel="logbook"
    orderby="date"
    sort="desc"
    dynamic="no"
    author_id="{member_id}" 
    {!-- so the channel entries is literally looking for "{member_id}" not the 
         value of the tag --} 
    disable="categories|category_fields|member_data|pagination"
}

This would explain why it works for the first statement (it gets parsed later and outputs the correct value) but doesn't work for the channel entries loop.

A possible solution you can have is installing this plugin and modify your embed tag to look something like this:

{embed="foo/bar" member_id="{logged_in_member_id}"}

This all has to do with ExpressionEngine's tricky parse order.

3
  • If you are curious, low (gotolow.com) has some really good documentation on the pitfalls of EE parse order – Johnathan Waters Jul 30 '14 at 17:38
  • 1
    Awesome, yes that was the problem. I'm using Solspace User so I wrapped the embed like this {exp:user:stats} {embed="inc/json_skills" member_id="{member_id}"} {/exp:user:stats} and now I'm getting the member_id parsed before hand. Thanks for your help Johnathan. – KoalaKid Jul 30 '14 at 20:10
  • Had the same scenario, this saved me, thank you both! – ByteMyPixel Sep 11 '17 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.