1

EE v2.7.2 Build Date: 20131008

I can't seem to find an elegant solution to make this work.

I've setup a channel name "test" with a field named 'test_field' (Text Input). I've created some entries with the test_field populated the same as entries title.

  • apple
  • banana
  • foo
  • bar

The goal is to use the search by parameter field 'test_field' and return 2 entries - "foo" and "bar".

You can see the Foo Bar plugin here: https://github.com/surprisehighway/foo_bar

Attempt 1

The single plugin tag {exp:foo_bar} returns the string 'foo|bar'. Looks like the entries tag is parsing before the foo_bar tag in the SQL query. LIKE "%{exp:foo\_bar}%". That is expected without parse inward?

{exp:channel:entries channel="test" dynamic="no" search:test_field="{exp:foo_bar}"}
    <h1>{title}</h1>
{/exp:channel:entries}

SELECT t.entry_id FROM exp_channel_titles AS t
LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id LEFT JOIN exp_channel_data AS wd ON wd.entry_id = t.entry_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id WHERE t.entry_id !='' AND t.site_id IN ('1')  AND t.entry_date < 1396016523  AND (t.expiration_date = 0 OR t.expiration_date > 1396016523) AND t.channel_id = '11' AND t.status = 'open' AND ( (wd.site_id=1 AND wd.field_id_111  LIKE "%{exp:foo\_bar}%") )ORDER BY t.sticky desc, t.entry_date desc, t.entry_id desc LIMIT 0, 100

Attempt 2

You would think that parse inward added to the entries tag would fix this. I'm still getting LIKE "%{exp:foo\_bar}%" when adding parse="inward" to the entries tag. This is not expected

EDIT: Should have checked my tweets. Ellislab said this will be fixed in the next release. I am still stumped with Attempt 5 in the meantime.

{exp:channel:entries channel="test" dynamic="no" search:test_field="{exp:foo_bar}" parse="inward"}
    <h1>{title}</h1>
{/exp:channel:entries}

SELECT t.entry_id FROM exp_channel_titles AS t
LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id LEFT JOIN exp_channel_data AS wd ON wd.entry_id = t.entry_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id WHERE t.entry_id !='' AND t.site_id IN ('1')  AND t.entry_date < 1396016672  AND (t.expiration_date = 0 OR t.expiration_date > 1396016672) AND t.channel_id = '11' AND t.status = 'open' AND ( (wd.site_id=1 AND wd.field_id_111  LIKE "%{exp:foo\_bar}%") )ORDER BY t.sticky desc, t.entry_date desc, t.entry_id desc LIMIT 0, 100

Attempt 3

Knowing from previous experience, EE's template parser struggles at times when plugin tags that are shoved into parameters. What if we make it a pair tag instead? The input value outputs directly to the foobar_result variable. We end up with LIKE "%{foobar\_result}%" in our SQL query.

The foo_bar:pair tag is a single row output using the ee()->TMPL->parse_variables_row method.

{exp:foo_bar:pair input="foo|bar"}
    {exp:channel:entries channel="test" dynamic="no" search:test_field="{foobar_result}"}
        <h1>{title}</h1>
    {/exp:channel:entries}
{/exp:foo_bar:pair}

SELECT t.entry_id FROM exp_channel_titles AS t
LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id LEFT JOIN exp_channel_data AS wd ON wd.entry_id = t.entry_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id WHERE t.entry_id !='' AND t.site_id IN ('1')  AND t.entry_date < 1396018169  AND (t.expiration_date = 0 OR t.expiration_date > 1396018169) AND t.channel_id = '11' AND t.status = 'open' AND ( (wd.site_id=1 AND wd.field_id_111  LIKE "%{foobar\_result}%") )ORDER BY t.sticky desc, t.entry_date desc, t.entry_id desc LIMIT 0, 100

Attempt 4

Let's add parse inward to the {exp:foo_bar:pair} tag so it's parsed before the entries tag. It works! But...see Example 5

{exp:foo_bar:pair input="foo|bar" parse="inward"}
    {exp:channel:entries channel="test" dynamic="no" search:test_field="{foobar_result}"}
        <h1>{title}</h1>
    {/exp:channel:entries}
{/exp:foo_bar:pair}

Attempt 5

Let's say we purposefully not find an entry result and return what is within the no_results conditional. My no_results condition is not working now because the foo_bar pair tag is returning a result. I need the no_result conditioning to work for the entries tag.

{exp:foo_bar:pair input="find_no_entry" parse="inward"}
    {exp:channel:entries channel="test" dynamic="no" search:test_field="{foobar_result}"}

        {if no_results}
            <h1>No results buddy</h1>
        {/if}

        <h1>{title}</h1>

    {/exp:channel:entries}
{/exp:foo_bar:pair}

Fini

Stuck at attempt 5 without getting more messy. Preferably without using another plugin. How do I solve this without getting more convoluted by wrapping it all with Stash? ;)

1

Actually, maybe you should consider just extending the Channel Entries tag. Might be the most elegant and lease parse-order-hoop-jumping way:

http://dmlogic.com/blog/extending-the-expression-engine-channel-module/

| improve this answer | |
0

Can you alter the plugin to return the entire search:test_field="" parameter? So that your channel entries tag opener looked like:

{exp:channel:entries channel="test" dynamic="no" parse="inward" {exp:foo_bar}}

I've definitely gotten plugins to work in this manner.

| 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.