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

“Advanced” 
Templating with ExpressionEngine

“Advanced” 
Templating with ExpressionEngine

Learn how to use Stash and creating simple plugins to advance your ExpressionEngine Templates

Trevor Davis

July 28, 2012
Tweet

More Decks by Trevor Davis

Other Decks in Technology

Transcript

  1. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. “ADVANCED” TEMPLATING by Trevor Davis at DCEERS on July , 
  2. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. @trevor_davis HI! I’M I work as a Front-End Developer at Viget. TREVOR DAVIS
  3. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. I. Stash II. Creating Simple Plugins WHAT WE WILL COVER
  4. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Set text and snippets of code ‎ Get them later on ‎ Include a layout ‎ Fill in the gaps STASH
  5. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. _layouts/base
  6. <!DOCTYPE html> <head> <title> {if {exp:stash:not_empty name="title"}} {exp:stash:get name="title"} |

    {/i } Site Name </title> </head> <body> {exp:stash:get name="content"} </body> </html>
  7. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. site/index
  8. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. RENDERED PAGE
  9. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. REAL EXAMPLE
  10. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Includes data from an entry in profile channel ‎ Includes entries from blog channel authored by that person VIGET.COM PROFILE PAGES
  11. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. THE OLD WAY
  12. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. THE NEW WAY
  13. {embed="_layouts/base"} {exp:stash:set parse_tags="yes"} {stash:blog_posts} {exp:channel:entries channel="blog" dynamic="no" username="{segment_3}" } <li><a

    href="/blog/{url_title}">{title}</a></li> {stash:num_posts}{absolute_results}{/stash:num_posts} {/exp:channel:entries} {/stash:blog_posts} {/exp:stash:set}
  14. {exp:channel:entries channel="profile" require_entry="yes" limit="1" } {exp:stash:set name="content"} <h1>{title}</h1> <h2>{profile_job_title}</h2> {profile_bio}

    {if {exp:stash:not_empty name="blog_posts"}} <h1>{exp:stash:get name="num_posts"}</b> Posts</h1> <ul> {exp:stash:get name="blog_posts"} </ul> {/i } {/exp:stash:set} {/exp:channel:entries}
  15. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. SERIOUSLY, GIVE IT A TRY
  16. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Our rule: no PHP in templates ‎ Performance implications ‎ Just messy ‎ Solution: create a plugin CREATING SIMPLE PLUGINS
  17. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. SIMPLE EXAMPLE
  18. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. A MORE COMPLEX EXAMPLE
  19. public function entry_count() { $channel_id = $this->EE->TMPL->fetch_param('channel_id', NULL); if($channel_id) {

    $query = $this->EE->db->select('total_entries') ->from('channels') ->where('channel_id', $channel_id) ->get(); if ($query->num_rows() > 0) { $row = $query->row(); return $row->total_entries; } } }
  20. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. PKG.IO
  21. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Multiple methods ‎ Won’t necessarily need them on other projects ‎ viget.com: 18 methods ‎ carrworkplaces.com: 4 methods SITE SPECIFIC PLUGINS
  22. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. Stash: devot-ee.com/add-ons/stash Pkg.io: pkg.io Sample Plugin: gist.github.com/3191839 web: trevordavis.net twitter: @trevor_davis Thanks! Let’s Connect Resources