Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

© 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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

  STASH

Slide 5

Slide 5 text

© 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

Slide 6

Slide 6 text

© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission. _layouts/base

Slide 7

Slide 7 text

{if {exp:stash:not_empty name="title"}} {exp:stash:get name="title"} | {/i } Site Name {exp:stash:get name="content"}

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

{embed="_layouts/base"} {exp:stash:set_value name="title" value="Homepage"} {exp:stash:set name="content"} Here is my content {/exp:stash:set}

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Homepage | Site Name Here is my content

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

© 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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

{embed="structure/header"} {exp:channel:entries channel="profile" require_entry="yes" limit="1" }

{title}

{profile_job_title}

{profile_bio} {embed="about/_blog_posts"} ... {/exp:channel:entries} {embed="structure/footer"}

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

{embed="_layouts/base"} {exp:stash:set parse_tags="yes"} {stash:blog_posts} {exp:channel:entries channel="blog" dynamic="no" username="{segment_3}" }
  • {title}
  • {stash:num_posts}{absolute_results}{/stash:num_posts} {/exp:channel:entries} {/stash:blog_posts} {/exp:stash:set}

    Slide 18

    Slide 18 text

    {exp:channel:entries channel="profile" require_entry="yes" limit="1" } {exp:stash:set name="content"}

    {title}

    {profile_job_title}

    {profile_bio} {if {exp:stash:not_empty name="blog_posts"}}

    {exp:stash:get name="num_posts"} Posts

      {exp:stash:get name="blog_posts"}
    {/i } {/exp:stash:set} {/exp:channel:entries}

    Slide 19

    Slide 19 text

    arrestedstills.tumblr.com CREDITS HOW I FELT AFTER LEARNING HOW TO USE STASH

    Slide 20

    Slide 20 text

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

    Slide 21

    Slide 21 text

      CREATING SIMPLE PLUGINS

    Slide 22

    Slide 22 text

    © 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

    Slide 23

    Slide 23 text

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

    Slide 24

    Slide 24 text

    Slide 25

    Slide 25 text

    {exp:vl_client:url_encode} http://viget.com/blog/awesome-entry-title {/exp:vl_client:url_encode}

    Slide 26

    Slide 26 text

    public function url_encode() { $tagdata = $this->EE->TMPL->tagdata; return urlencode(trim($tagdata)); }

    Slide 27

    Slide 27 text

    http%3A%2F%2Fviget.com%2Fblog%2Fawesome-entry-title

    Slide 28

    Slide 28 text

    © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission. A MORE COMPLEX EXAMPLE

    Slide 29

    Slide 29 text

    {exp:vl_client:entry_count channel_id="4"}

    Slide 30

    Slide 30 text

    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; } } }

    Slide 31

    Slide 31 text

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

    Slide 32

    Slide 32 text

    No content

    Slide 33

    Slide 33 text

    © 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

    Slide 34

    Slide 34 text

    © 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