Parse Order Pro

Parse Order Pro

Be a Pro with ExpressionEngine's Parse Order.

A347386377e120e3230403d2558c1a0d?s=128

Lodewijk Schutte

October 12, 2011
Tweet

Transcript

  1. 4.
  2. 5.

    ExpressionEngine’s Parse Order In what order does EE parse its

    variables and tags? Read URI to determine template Get template from DB, check permissions & authentication Get template from file Return static template 1. Parse snippets / global variables, segment variables and embed variables * Parse date string constants Parse {template_edit_date} and {current_time} If present, get cached template, then go to #7 2. Parse PHP on Input 3. Parse simple conditionals: segment, embed, global variables 4. Assign and parse preload_replace variables 5. Parse module and plugin tags 6. Parse PHP on Output Write cache file 7. Parse advanced conditionals 8. Process embedded templates Redirect 9. Parse User Defined global variables and others: {hits} {ip_address} {gzip_mode} {app_version} {group_title} {member_group} gotolow.com/parse-order
  3. 6.
  4. 8.
  5. 16.
  6. 17.

    Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} {a} {d} {b} {a} {c} {c} {e} {e}
  7. 18.

    Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 {d} {b} 1 {c} {c} {e} {e}
  8. 19.

    Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 {d} 2 1 {c} {c} {e} {e}
  9. 20.

    Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 {d} 2 1 {d} {d} {e} {e}
  10. 21.

    Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 3 2 1 3 3 {e} {e}
  11. 22.

    Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 3 2 1 3 3 {a} {a}
  12. 23.

    Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 3 2 1 3 3 {a} {a}
  13. 24.
  14. 28.
  15. 33.

    Global Variables •Parsed Early • Snippets • Config variables •

    Segment variables •Parsed Late • User Defined Global Variables • "Standard Global Variables" http://bit.ly/standard-global-vars
  16. 35.
  17. 36.

    All Variables snippets config  vars segment  vars embed  vars preload

     replace  vars {exp:tags}  local  vars  {/exp:tags} user  defined  vars standard  vars
  18. 37.
  19. 44.

    Tags & Local vars {gv_header} <h1>{sn_news_title}  containing  {username}</h1> {exp:channel:entries  channel="news"

       search:cf_summary="{username}"}        <h2>{title}</h2>        {cf_summary} {/exp:channel:entries} {gv_footer}
  20. 47.
  21. 48.

    Standard Global vars <html> <head>    <title>{sn_{segment_1}_title}  -­‐  {site_name}</title> </head>

    <body> <h1>{sn_news_title}  containing  {username}</h1> <p>&copy;  {current_date  format="%Y"}</p> </body> </html>
  22. 49.

    <html> <head>    <title>{sn_{segment_1}_title}  -­‐  EE  Outsider</title> </head> <body> <h1>{sn_news_title}

     containing  kennymeyers</h1> <p>&copy;  {current_date  format="%Y"}</p> </body> </html>
  23. 54.

    Segment vars <html> <head>    <title>{gv_{segment_1}_title}</title> </head> <body> {preload_replace:pre_limit="1"} {preload_replace:pre_body="{cf_summary}"}

    {exp:channel:entries  channel="{segment_1}"    limit="{pre_limit}"}        <h2>{title}</h2>        {pre_body} {/exp:channel:entries} {gv_footer}
  24. 56.

    Preload Replace vars <html> <head>    <title>{gv_news_title}</title> </head> <body> {preload_replace:pre_limit="1"}

    {preload_replace:pre_body="{cf_summary}"} {exp:channel:entries  channel="news"    limit="{pre_limit}"}        <h2>{title}</h2>        {pre_body} {/exp:channel:entries} {gv_footer}
  25. 58.

    Tags & Local vars <html> <head>    <title>{gv_news_title}</title> </head> <body>

    {exp:channel:entries  channel="news"  limit="1"}    <h2>{title}</h2>    {cf_summary} {/exp:channel:entries} {gv_footer}
  26. 59.

    <html> <head>    <title>{gv_news_title}</title> </head> <body>    <h2>Missing:  Kenny  Meyers</h2>

       <p>Last  seen  at  Pier  39  San  Francisco,          hanging  out  with  some  friends.</p> {gv_footer}
  27. 60.

    User Defined Global vars <html> <head>    <title>{gv_news_title}</title> </head> <body>

       <h2>Missing:  Kenny  Meyers</h2>    <p>Last  seen  at  Pier  39  San  Francisco,          hanging  out  with  some  friends.</p> {gv_footer}
  28. 61.

    <html> <head>    <title>The  News</title> </head> <body>    <h2>Missing:  Kenny

     Meyers</h2>    <p>Last  seen  at  Pier  39  San  Francisco,          hanging  out  with  some  friends.</p> <p>&copy;  {site_name}</p> </body> </html>
  29. 62.

    Standard Global vars <html> <head>    <title>The  News</title> </head> <body>

       <h2>Missing:  Kenny  Meyers</h2>    <p>Last  seen  at  Pier  39  San  Francisco,          hanging  out  with  some  friends.</p> <p>&copy;  {site_name}</p> </body> </html>
  30. 63.

    <html> <head>    <title>The  News</title> </head> <body>    <h2>Missing:  Kenny

     Meyers</h2>    <p>Last  seen  at  Pier  39  San  Francisco,          hanging  out  with  some  friends.</p> <p>&copy;  EE  Outsider</p> </body> </html>
  31. 64.
  32. 67.

    Simple Conditionals •Only work with early parsed variables * •Only

    work with one operand •Only work without if:else statement •If so, are parsed before tags *) Except Preload Replace variables
  33. 68.

    Advanced Conditionals •All other conditionals * •Converted to PHP, then

    evaluated •Are parsed after tags *) Except special conditionals
  34. 70.

    Special Conditionals •Parsed during and by tags •For example: •

    {if no_results} {/if} • {if next_page} {/if} • etc. •But most conditionals in tags are actually advanced conditionals
  35. 73.

    {if  segment_3  ==  'by-­‐category'}    {exp:channel:categories  channel="bars"}      

         <a  href="#">{category_name}</a>    {/exp:channel:categories} {if:else}  {exp:channel:entries        channel="bars{if  logged_in}|foos{/if}"}            <h2>{title}</h2>            {if  no_results}Nothing  found!{/if}    {/exp:channel:entries} {/if}
  36. 74.

    Simple conditionals {if  segment_3  ==  'by-­‐category'}    {exp:channel:categories  channel="bars"}  

             <a  href="#">{category_name}</a>    {/exp:channel:categories} {if:else}  {exp:channel:entries        channel="bars{if  logged_in}|foos{/if}"}            <h2>{title}</h2>            {if  no_results}Nothing  found!{/if}    {/exp:channel:entries} {/if}    
  37. 75.

    {if  segment_3  ==  'by-­‐category'}    {exp:channel:categories  channel="bars"}      

         <a  href="#">{category_name}</a>    {/exp:channel:categories} {if:else}  {exp:channel:entries        channel="bars{if  logged_in}|foos{/if}"}            <h2>{title}</h2>            {if  no_results}Nothing  found!{/if}    {/exp:channel:entries} {/if}
  38. 76.

    Tags & Special conditionals {if  segment_3  ==  'by-­‐category'}    {exp:channel:categories

     channel="bars"}            <a  href="#">{category_name}</a>    {/exp:channel:categories} {if:else}  {exp:channel:entries        channel="bars{if  logged_in}|foos{/if}"}            <h2>{title}</h2>            {if  no_results}Nothing  found!{/if}    {/exp:channel:entries} {/if}
  39. 77.

    {if  segment_3  ==  'by-­‐category'}            <a

     href="#">Brooklyn</a>            <a  href="#">Manhattan</a>            <a  href="#">Queens</a> {if:else}            Nothing  found! {/if}
  40. 78.

    Advanced conditionals {if  segment_3  ==  'by-­‐category'}        

       <a  href="#">Brooklyn</a>            <a  href="#">Manhattan</a>            <a  href="#">Queens</a> {if:else}            Nothing  found! {/if}
  41. 81.

    {if  logged_in}    {exp:channel:entries  channel="bars"        {if  segment_3

     !=  'all'}limit="2"{/if}}            <h2>{title}</h2>            {if  cf_bar_is_awesome  ==  'y'}                This  bar  is  awesome!            {/if}    {/exp:channel:entries} {/if} {if  sn_show_foos  ==  'y'}    {exp:channel:entries  channel="foos"}        <h3>{title}</h3>        {if  no_results}No  foos  found!{/if}    {/exp:channel:entries} {/if}
  42. 82.

    Simple conditionals {if  logged_in}    {exp:channel:entries  channel="bars"      

     {if  segment_3  !=  'all'}limit="2"{/if}}            <h2>{title}</h2>            {if  cf_bar_is_awesome  ==  'y'}                This  bar  is  awesome!            {/if}    {/exp:channel:entries} {/if} {if  sn_show_foos  ==  'y'}    {exp:channel:entries  channel="foos"}        <h3>{title}</h3>        {if  no_results}No  foos  found!{/if}    {/exp:channel:entries} {/if}
  43. 83.

    {if  logged_in}    {exp:channel:entries  channel="bars"        limit="2"}  

             <h2>{title}</h2>            {if  cf_bar_is_awesome  ==  'y'}                This  bar  is  awesome!            {/if}    {/exp:channel:entries} {/if}    {exp:channel:entries  channel="foos"}        <h3>{title}</h3>        {if  no_results}No  foos  found!{/if}    {/exp:channel:entries}
  44. 84.

    Tags & Special conditionals {if  logged_in}    {exp:channel:entries  channel="bars"  

         limit="2"}            <h2>{title}</h2>            {if  cf_bar_is_awesome  ==  'y'}                This  bar  is  awesome!            {/if}    {/exp:channel:entries} {/if}    {exp:channel:entries  channel="foos"}        <h3>{title}</h3>        {if  no_results}No  foos  found!{/if}    {/exp:channel:entries}
  45. 85.

    {if  logged_in}            <h2>Bar  One</h2>  

             {if  'n'  ==  'y'}                This  bar  is  awesome!            {/if}            <h2>Bar  Two</h2>            {if  'y'  ==  'y'}                This  bar  is  awesome!            {/if} {/if}        <h3>Foo  One</h3>        <h3>Foo  Two</h3>        <h3>Foo  Three</h3>
  46. 86.

    Advanced conditionals {if  logged_in}            <h2>Bar

     One</h2>            {if  'n'  ==  'y'}                This  bar  is  awesome!            {/if}            <h2>Bar  Two</h2>            {if  'y'  ==  'y'}                This  bar  is  awesome!            {/if} {/if}        <h3>Foo  One</h3>        <h3>Foo  Two</h3>        <h3>Foo  Three</h3>
  47. 87.

               <h2>Bar  One</h2>      

         <h2>Bar  Two</h2>                This  bar  is  awesome!        <h3>Foo  One</h3>        <h3>Foo  Two</h3>        <h3>Foo  Three</h3>
  48. 88.
  49. 92.

    Plugin Tags •Look inside for other tags first •If found,

    that tag is parsed first •Except if it's a plugin tag, then see previous •Cancel this behaviour with parse="inward"
  50. 94.

    {exp:channel:entries  channel="feeds"  limit="3"}    <h2>{title}</h2>    {exp:magpie  url="{feed_url}"}    

       {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie} {/exp:channel:entries}
  51. 95.

    {exp:channel:entries  channel="feeds"  limit="3"}    <h2>{title}</h2>    {exp:magpie  url="{feed_url}"}    

       {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie} {/exp:channel:entries}
  52. 96.

       <h2>First  title</h2>    {exp:magpie  url="http://one.com/rss"}        {items}

               <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}    <h2>Second  title</h2>    {exp:magpie  url="http://two.com/rss"}        {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}
  53. 97.

       <h2>First  title</h2>    {exp:magpie  url="http://one.com/rss"}        {items}

               <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}    <h2>Second  title</h2>    {exp:magpie  url="http://two.com/rss"}        {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}
  54. 98.

       <h2>First  title</h2>    {exp:magpie  url="http://one.com/rss"}        {items}

               <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}    <h2>Second  title</h2>    {exp:magpie  url="http://two.com/rss"}        {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}
  55. 99.

       <h2>First  title</h2>    {exp:magpie  url="http://one.com/rss"}        {items}

               <h3>{magpie:title}</h3>            {magpie:content}        {/items}    {/exp:magpie}    <h2>Second  title</h2>    {exp:magpie  url="http://two.com/rss"}        {items}            <h3>{magpie:title}</h3>            {magpie:content}        {/items}    {/exp:magpie}
  56. 100.

       <h2>First  title</h2>    {exp:magpie  url="http://one.com/rss"}        {items}

               <h3>{magpie:title}</h3>            {magpie:content}        {/items}    {/exp:magpie}    <h2>Second  title</h2>    {exp:magpie  url="http://two.com/rss"}        {items}            <h3>{magpie:title}</h3>            {magpie:content}        {/items}    {/exp:magpie}
  57. 101.

       <h2>First  title</h2>            <h3>Title  1.1</h3>

               <p>Lorem  ipsum  <a  href="#">dolor</a>  sit  amet</p>            <h3>Title  1.2</h3>            <p>The  lazy  dog  jumped  over  the  <em>fox</em></p>    <h2>Second  title</h2>            <h3>Title  2.1</h3>            <embeds  and  malicious  code>            <h3>Title  2.2</h3>            <blinks  and  marquees>
  58. 103.

    {exp:channel:entries  channel="feeds"  limit="3"}    <h2>{title}</h2>    {exp:magpie  url="{feed_url}"  parse="inward"}  

         {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie} {/exp:channel:entries}
  59. 104.

    {exp:channel:entries  channel="feeds"  limit="3"}    <h2>{title}</h2>    {exp:magpie  url="{feed_url}"  parse="inward"}  

         {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie} {/exp:channel:entries}
  60. 105.

       <h2>First  title</h2>    {exp:magpie  url="http://one.com/rss"  parse="inward"}      

     {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}    <h2>Second  title</h2>    {exp:magpie  url="http://two.com/rss"  parse="inward"}        {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}
  61. 106.

       <h2>First  title</h2>    {exp:magpie  url="http://one.com/rss"  parse="inward"}      

     {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}    <h2>Second  title</h2>    {exp:magpie  url="http://two.com/rss"  parse="inward"}        {items}            <h3>{magpie:title}</h3>            {exp:strip_html}{magpie:content}{/exp:strip_html}        {/items}    {/exp:magpie}
  62. 107.

       <h2>First  title</h2>            <h3>Title  1.1</h3>

               {exp:strip_html}<p>Lorem  ipsum  <a  href="#">            dolor</a>  sit  amet</p>{/exp:strip_html}            <h3>Title  1.2</h3>            {exp:strip_html}<p>The  lazy  dog  jumped  over            the  <em>fox</em></p>{/exp:strip_html}    <h2>Second  title</h2>            <h3>Title  2.1</h3>            {exp:strip_html}<embeds>{/exp:strip_html}            <h3>Title  2.2</h3>            {exp:strip_html}<marquees>{/exp:strip_html}
  63. 108.

       <h2>First  title</h2>            <h3>Title  1.1</h3>

               {exp:strip_html}<p>Lorem  ipsum  <a  href="#">            dolor</a>  sit  amet</p>{/exp:strip_html}            <h3>Title  1.2</h3>            {exp:strip_html}<p>The  lazy  dog  jumped  over            the  <em>fox</em></p>{/exp:strip_html}    <h2>Second  title</h2>            <h3>Title  2.1</h3>            {exp:strip_html}<embeds>{/exp:strip_html}            <h3>Title  2.2</h3>            {exp:strip_html}<marquees>{/exp:strip_html}
  64. 109.

       <h2>First  title</h2>            <h3>Title  1.1</h3>

               Lorem  ipsum  dolor  sit  amet            <h3>Title  1.2</h3>            The  lazy  dog  jumped  over  the  fox    <h2>Second  title</h2>            <h3>Title  2.1</h3>            ...            <h3>Title  2.2</h3>            ...
  65. 110.

    A Parse Order Pro •...can identify markers •...knows when they

    are parsed •...knows how to nest them •...and will always...
  66. 112.