Trying to obtain the id of a collection item to filter against

  • I have perch collection created to manage news. The user has the ability to select a featured news article:


    Code
    1. <perch:related id="relatedNews" collection="News Articles" label="Featured News Article" max="1"></perch:related>

    I'm obtaining the id of the selected article ok:


    Code
    1. <perch:related id="relatedNews" collection="News Articles" label="Featured News Article" max="1">
    2. <perch:content id="_id"/>
    3. </perch:related>

    However trying to filter against this isn't working, I'm getting no results:


    Code
    1. perch_collection('News Articles', [
    2. 'template'=>'_news/news_list.html',
    3. 'filter' => '_id',
    4. 'match' => 'eq',
    5. 'value' => $featureArticle
    6. ]);

    Can anyone shed any light on why this my be?

  • Fixed the issue, the whitespace in the template was the problem.


    Changing this:


    Code
    1. <perch:related id="relatedNews" collection="News Articles" label="Featured News Article" max="1">
    2. <perch:content id="_id"/>
    3. </perch:related>


    to this:


    Code
    1. <perch:related id="relatedNews" collection="News Articles" label="Featured News Article" max="1"><perch:content id="_id"/></perch:related>


    Fixed the issue.