Content filter that test if related item has a value

Options

Can I make a content filter with a condition to test if a related item field is empty (or not)?

For example, I have an Event content-type and a Employee content-type. The Event has a speakers field that is optional and a related item to multiple Employees. I would to create a generic list of Events that have speakers.

Or if it helps, here is a SQL statement for it:

SELECT *

FROM Events INNER JOIN

Events_relatedItem_speakers ON Events.id = Events_relatedItem_speakers.event_id

GROUP BY Events.id

WHERE ...

Tagged:

Comments

  • Yep, CMS has an undocumented method of object access of the form ${object.contentproperty}.

    Within the events content type, create a new display template with the contents:

    <p>Events with Speakers:</p>

    <p><t:list>

    <t:if test="speakers.length > 0">

    <a href="$"><t:value id="title"></t:value></a><br />

    </t:if>

    </t:list></p>

    And then insert that list with that template into your page.

  • Jim Drey:

    Yep, CMS has an undocumented method of object access of the form ${object.contentproperty}.

    Within the events content type, create a new display template with the contents:

    <p>Events with Speakers:</p>

    <p><t:list>

    <t:if test="speakers.length > 0">

    <a href="$"><t:value id="title"></t:value></a><br />

    </t:if>

    </t:list></p>

    And then insert that list with that template into your page.

    The only problem is if I want to only show the last five Events with speakers, and the three of the last five did not have speakers, then it will only show two Events as opposed to five.

  • Really? I'd call that a bug in CMS - list elements with a maximum number of items listed should only count items that are output. Bleh.

    Okay, you can still pull this off. Since CMS offers no real flow control, you'll need to use a temp variable. Apply sorting options in the list UI.

    <p>Events with Speakers:</p>

    <t:set id="x" value="0" />

    <p><t:list>

    <t:if test="x < 5 && speakers.length > 0">

    <a href="$"><t:value id="title"></t:value></a><br />

    </t:if>

    <t:set id="x" value="x + 1" />

    </t:list></p>

  • Jim Drey:

    Really? I'd call that a bug in CMS - list elements with a maximum number of items listed should only count items that are output. Bleh.

    Okay, you can still pull this off. Since CMS offers no real flow control, you'll need to use a temp variable. Apply sorting options in the list UI.

    <p>Events with Speakers:</p>

    <t:set id="x" value="0" />

    <p><t:list>

    <t:if test="x < 5 && speakers.length > 0">

    <a href="$"><t:value id="title"></t:value></a><br />

    </t:if>

    <t:set id="x" value="x + 1" />

    </t:list></p>

    I don't know if I would call it a bug. When I set the max length or X, I am asking for t:list to run X times (or less if there is not enough)

    each with an item. It is then up to me to determine what to do with the items.

    I might not even want to output them; I might want to use t:set with them.

  • Seamus Leahy:

    I don't know if I would call it a bug. When I set the max length or X, I am asking for t:list to run X times (or less if there is not enough)

    each with an item. It is then up to me to determine what to do with the items.

    I might not even want to output them; I might want to use t:set with them.

    I s'pose you're right. Hope my code still helped, though!

Categories