ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Global variables from custom fields not showing in search results

October 18, 2011 7:43am

Subscribe [2]
  • #1 / Oct 18, 2011 7:43am

    TheBlackHole

    72 posts

    Hi all,

    This has got parsing order written all over it in my opinion, but I have no idea how to solve it.

    I have allowed EE code (using the plugin) so that a can use global variables for common reused content like a phone number for example. So I can add {gv_phone} anywhere in a text field and it will display the correct content on the page.

    But on the search results page it just outputs {gv_phone}, any ideas?

    By the way, if someone can think of a better way to tackle this I’m happy to hear about it!

    Many thanks

  • #2 / Oct 18, 2011 9:59am

    glenndavisgroup

    436 posts

    Hi TheBlackHole,

    This should work. What version and build of EE are you running? Can you post a sample of your code?

    Thank you,

    Mike

  • #3 / Oct 18, 2011 10:22am

    TheBlackHole

    72 posts

    Typical, as soon as you said it should work. I changed the order of the {exp:allow_eecode} and the {exp:search:search_results} code and now it works, I was sure I’d tried this!

    Changed it from…

    <dl id="results">
     {exp:allow_eecode}
      {exp:search:search_results}
       {exp:search_hilite}
    
       <dt><a href="http://{page_url}">{title}</a></dt>
       <dd class="excerpt">{excerpt}</dd>
    
       {/exp:search_hilite}   
      {/exp:search:search_results}
     {/exp:allow_eecode}
    </dl>

    To…

    <dl id="results">
     {exp:search:search_results}
      {exp:search_hilite}
       {exp:allow_eecode}
       
       <dt><a href="http://{page_url}">{title}</a></dt>
       <dd class="excerpt">{excerpt}</dd>
       
       {/exp:allow_eecode}
      {/exp:search_hilite}   
     {/exp:search:search_results}
    </dl>

    ... which makes total sense, good to see I can still make rookie mistakes!

    One caveat I have found is that if someone searches for part of the variable (which in this case is {gv_phone}) like “phone” for example. The search results display the unparsed variable. Do you see a way around this?

    Many thanks

     

  • #4 / Oct 18, 2011 10:29am

    glenndavisgroup

    436 posts

    This could be due to global vars being parsed last. This might be better if snippets are used here as they are parsed first.

  • #5 / Oct 18, 2011 10:43am

    TheBlackHole

    72 posts

    I just tried using a snippet and it wasn’t being parsed at all (even on a non-search results page).

  • #6 / Oct 18, 2011 10:52am

    glenndavisgroup

    436 posts

    Are you sure it’s not a cache issue?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases