4

If I am using playa to output the relationships from 2 fields:

{exp:playa:children field="employee_board_memberships|employee_investments"}
    ...
{/exp:playa:children}

Is there any way inside of the loop to identify which (or both) fields the entry is coming from?

{exp:playa:children field="employee_board_memberships|employee_investments"}
    {if from_employee_board_memberships}
        This was from the employee_board_memberships field
    {/if}

    {if from_employee_investments}
        This was from the employee_investments field
    {/if}
{/exp:playa:children}
3

The answer is No. {exp:playa:children} just figures out the IDs of the entries that should be output, and passes them + the inner template code to Channel->entries(), which handles actually grabbing the entries and parsing the template code. So there’s no way for Playa to tell it to add any extra per-entry variables into the mix. (This is why the {parent:xyz} and {child:xyz} values only work if you’re grabbing the children/parents of a single entry at a time.)

| improve this answer | |
  • I started to dig into the module last night and figured out some of this stuff as well. Thanks for expanding, definitely useful to understand how the module actually grabs the data. – Trevor Davis Jan 10 '13 at 22:40
2

Ended up solving this a different way. I stashed the IDs for each relationship and then did a regex match with switchee:

{!-- Store the ids for the playa company relationships --}
{exp:stash:set name="board_memberships_ids" parse_tags="yes"}
    ,{employee_board_memberships:child_ids delimiter=","},
{/exp:stash:set}

{exp:stash:set name="investments_ids" parse_tags="yes"}
    ,{employee_investments:child_ids delimiter=","},
{/exp:stash:set}

{!-- Set the related companies list --}
{exp:playa:children field="employee_board_memberships|employee_investments"}
    {exp:stash:append_list name="employees_companies" parse_tags="yes"}
        {stash:item_class}
            {switchee variable="stash:board_memberships_ids" parse="inward"}
                {case value="#,{entry_id},#"}board-members{/case}
            {/switchee}

            {switchee variable="stash:investments_ids" parse="inward"}
                {case value="#,{entry_id},#"}investments{/case}
            {/switchee}

            {if company_investment_stage == "public"}ipos{/if}

            {if company_investment_stage == "acquired-merged"}acquisitions{/if}
         {/stash:item_class}
        {stash:item_sort}{title}{/stash:item_sort}
        {stash:item_content}
            <a href="/portfolio/{url_title}" class="modal-trigger">{title}</a>
        {/stash:item_content}
    {/exp:stash:append_list}
{/exp:playa:children}
| improve this answer | |
-1

You should be able to get by easily by using the following:

{exp:playa:children field="employee_board_memberships|employee_investments"}
    {if employee_board_memberships}
        This was from the employee_board_memberships field
    {/if}

    {if employee_investments}
        This was from the employee_investments field
    {/if}
{/exp:playa:children}

… shouldn’t you? You’re in essence just testing whether or not that child has either of those fields filled out, so it should return the code you want. You don’t need the from_ in your example code.

| improve this answer | |
  • This Playa tag is pulling related entries in the Company channel, while employee_board_memberships and employee_investments are custom fields in the Employee channel. – Trevor Davis Jan 10 '13 at 3:12
  • Right. So then it should return true or false in either of these situations, should they not? – Christopher Kennedy Jan 10 '13 at 3:13
  • But those fields mean nothing to the related entry inside of the Playa tag. – Trevor Davis Jan 10 '13 at 3:14
-1

This is untested, but maybe try using the var_prefix and nest the {exp:playa:children} tags like so:

{exp:playa:children field="employee_board_memberships" var_prefix="ebm"}
    {exp:playa:children field="employee_investments" var_prefix="ei"}
    {if ebm:title}
        This was from the employee_board_memberships field
    {/if}

    {if ei:title}
        This was from the employee_investments field
    {/if}
    {/exp:playa:children}
{/exp:playa:children}
| improve this answer | |

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.