Share
Embed
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
113 slides
-
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 -
How does parsing work? •Document (template) •Markers (variables and tags)
•Values (data) •Find & Replace (parsing) -
Parse Order {a} => 1 {b} => 2 {c} =>
3 {a} {b} {a} {c} {c} -
Parse Order {a} => 1 {b} => 2 {c} =>
3 1 {b} 1 {c} {c} -
Parse Order {a} => 1 {b} => 2 {c} =>
3 1 2 1 {c} {c} -
Parse Order {a} => 1 {b} => 2 {c} =>
3 1 2 1 3 3 -
Parse Order {a} => 1 {b} => 2 {c} =>
3 1 2 1 3 3 -
Parse Order {a} => 1 {b} => 2 {c} =>
{d} {d} => 3 {e} => {a} {a} {d} {b} {a} {c} {c} {e} {e} -
Parse Order {a} => 1 {b} => 2 {c} =>
{d} {d} => 3 {e} => {a} 1 {d} {b} 1 {c} {c} {e} {e} -
Parse Order {a} => 1 {b} => 2 {c} =>
{d} {d} => 3 {e} => {a} 1 {d} 2 1 {c} {c} {e} {e} -
Parse Order {a} => 1 {b} => 2 {c} =>
{d} {d} => 3 {e} => {a} 1 {d} 2 1 {d} {d} {e} {e} -
Parse Order {a} => 1 {b} => 2 {c} =>
{d} {d} => 3 {e} => {a} 1 3 2 1 3 3 {e} {e} -
Parse Order {a} => 1 {b} => 2 {c} =>
{d} {d} => 3 {e} => {a} 1 3 2 1 3 3 {a} {a} -
Parse Order {a} => 1 {b} => 2 {c} =>
{d} {d} => 3 {e} => {a} 1 3 2 1 3 3 {a} {a} -
Global Variables •Parsed Early • Snippets • Config variables •
Segment variables •Parsed Late • User Defined Global Variables • "Standard Global Variables" http://bit.ly/standard-global-vars -
Regional Variables •Parsed Early • Embed variables • Preload replace
variables * *) Parsed early-ish -
Local Variables •Parsed during Tags •Can be more complex •
Variable parameters • Variable pairs -
All Variables snippets config vars segment vars embed vars preload
replace vars {exp:tags} local vars {/exp:tags} user defined vars standard vars -
{gv_header} <h1>{sn_{segment_1}_title} containing {username}</h1> {exp:channel:entries channel="{segment_1}" search:cf_summary="{username}"}
<h2>{title}</h2> {cf_summary} {/exp:channel:entries} {gv_footer} -
Snippets {gv_header} <h1>{sn_{segment_1}_title} containing {username}</h1> {exp:channel:entries channel="{segment_1}" search:cf_summary="{username}"}
<h2>{title}</h2> {cf_summary} {/exp:channel:entries} {gv_footer} -
{gv_header} <h1>{sn_{segment_1}_title} containing {username}</h1> {exp:channel:entries channel="{segment_1}" search:cf_summary="{username}"}
<h2>{title}</h2> {cf_summary} {/exp:channel:entries} {gv_footer} -
Segment vars {gv_header} <h1>{sn_{segment_1}_title} containing {username}</h1> {exp:channel:entries channel="{segment_1}" search:cf_summary="{username}"}
<h2>{title}</h2> {cf_summary} {/exp:channel:entries} {gv_footer} -
{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} -
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} -
<html> <head> <title>{sn_{segment_1}_title} -‐ {site_name}</title> </head> <body> <h1>{sn_news_title} containing
{username}</h1> <p>© {current_date format="%Y"}</p> </body> </html> -
Standard Global vars <html> <head> <title>{sn_{segment_1}_title} -‐ {site_name}</title> </head>
<body> <h1>{sn_news_title} containing {username}</h1> <p>© {current_date format="%Y"}</p> </body> </html> -
<html> <head> <title>{sn_{segment_1}_title} -‐ EE Outsider</title> </head> <body> <h1>{sn_news_title}
containing kennymeyers</h1> <p>© {current_date format="%Y"}</p> </body> </html> -
<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} -
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} -
<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} -
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} -
<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} -
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} -
<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} -
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} -
<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>© {site_name}</p> </body> </html> -
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>© {site_name}</p> </body> </html> -
<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>© EE Outsider</p> </body> </html> -
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 -
Advanced Conditionals •All other conditionals * •Converted to PHP, then
evaluated •Are parsed after tags *) Except special conditionals -
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 -
{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} -
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} -
{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} -
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} -
{if segment_3 == 'by-‐category'} <a
href="#">Brooklyn</a> <a href="#">Manhattan</a> <a href="#">Queens</a> {if:else} Nothing found! {/if} -
Advanced conditionals {if segment_3 == 'by-‐category'}
<a href="#">Brooklyn</a> <a href="#">Manhattan</a> <a href="#">Queens</a> {if:else} Nothing found! {/if} -
{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} -
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} -
{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} -
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} -
{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> -
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> -
<h2>Bar One</h2>
<h2>Bar Two</h2> This bar is awesome! <h3>Foo One</h3> <h3>Foo Two</h3> <h3>Foo Three</h3> -
Module Tags •Parsed from the document root inwards •Repeated until
no tags are left -
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" -
{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} -
{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} -
<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} -
<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} -
<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} -
<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} -
<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} -
<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> -
{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} -
{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} -
<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} -
<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} -
<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} -
<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} -
<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> ... -
A Parse Order Pro •...can identify markers •...knows when they
are parsed •...knows how to nest them •...and will always...