Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Parse Order Pro

Parse Order Pro

Be a Pro with ExpressionEngine's Parse Order.

Lodewijk Schutte

October 12, 2011
Tweet

More Decks by Lodewijk Schutte

Other Decks in Technology

Transcript

  1. 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
  2. Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} {a} {d} {b} {a} {c} {c} {e} {e}
  3. Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 {d} {b} 1 {c} {c} {e} {e}
  4. Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 {d} 2 1 {c} {c} {e} {e}
  5. Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 {d} 2 1 {d} {d} {e} {e}
  6. Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 3 2 1 3 3 {e} {e}
  7. Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 3 2 1 3 3 {a} {a}
  8. Parse Order {a}  =>  1 {b}  =>  2 {c}  =>

     {d} {d}  =>  3 {e}  =>  {a} 1 3 2 1 3 3 {a} {a}
  9. Global Variables •Parsed Early • Snippets • Config variables •

    Segment variables •Parsed Late • User Defined Global Variables • "Standard Global Variables" http://bit.ly/standard-global-vars
  10. All Variables snippets config  vars segment  vars embed  vars preload

     replace  vars {exp:tags}  local  vars  {/exp:tags} user  defined  vars standard  vars
  11. 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}
  12. 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>
  13. <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>
  14. 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}
  15. 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}
  16. 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}
  17. <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}
  18. 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}
  19. <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>
  20. 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>
  21. <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>
  22. 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
  23. Advanced Conditionals •All other conditionals * •Converted to PHP, then

    evaluated •Are parsed after tags *) Except special conditionals
  24. 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
  25. {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}
  26. 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}    
  27. {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}
  28. 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}
  29. {if  segment_3  ==  'by-­‐category'}            <a

     href="#">Brooklyn</a>            <a  href="#">Manhattan</a>            <a  href="#">Queens</a> {if:else}            Nothing  found! {/if}
  30. Advanced conditionals {if  segment_3  ==  'by-­‐category'}        

       <a  href="#">Brooklyn</a>            <a  href="#">Manhattan</a>            <a  href="#">Queens</a> {if:else}            Nothing  found! {/if}
  31. {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}
  32. 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}
  33. {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}
  34. 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}
  35. {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>
  36. 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>
  37.            <h2>Bar  One</h2>      

         <h2>Bar  Two</h2>                This  bar  is  awesome!        <h3>Foo  One</h3>        <h3>Foo  Two</h3>        <h3>Foo  Three</h3>
  38. 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"
  39. {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}
  40. {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}
  41.    <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}
  42.    <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}
  43.    <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}
  44.    <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}
  45.    <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}
  46.    <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>
  47. {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}
  48. {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}
  49.    <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}
  50.    <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}
  51.    <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}
  52.    <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}
  53.    <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>            ...
  54. A Parse Order Pro •...can identify markers •...knows when they

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