Search code examples
phpparsingexpressionengine

Parsing variable from variables in search results


For creating search results I've got a channel field where the path to the page is stored (eg. /products/bikes). Each entry has it's own path.

Because there are different channels, every channel has it's uniquely named channel field. For the channel "products" it's: {products_search_path_nl}.

Within the results page {exp:search:search_results} the field is dynamically created like this: {channel_short_name}_search_path_{language} which is displayed as products_search_path_nl.

The issue is that it does not get parsed. After looking at EE's parse order I've tried:

  • using it as a snippet
  • assigning it to a PHP variable and outputting it later on
  • changing PHP parsing stage (input / output)
  • embedding it using a template {embed="search/uri_embed"}
  • embedding it using a template and a template variable {embed="search/uri_embed" passed_var="{channel_short_name}"}
  • using it within a simple conditional statement {if "1" == "1"}

Thanks for reading! Any help would be appriciated!


Solution

  • Thanks to Low's suggestion I used a loop, since this seems impossible to solve in a propper manner.

        {if "{channel_short_name}" == "news"}
            {if "{news_search_path_{language}}" != ""}
                <h3><a href="{base_url}{news_search_path_{language}}{url_title}">{title} </a></h3>
                {excerpt}
            {/if}
    
        {if:elseif "{channel_short_name}" == "products"}    
            {if "{products_search_path_{language}}" != ""}
                <h3><a href="{base_url}{products_search_path_{language}}{url_title}">{title} </a> </h3>
                {excerpt}
            {/if}
    
         // ....... and so on