Learn how to use Stash and creating simple plugins to advance your ExpressionEngine Templates
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.“ADVANCED”TEMPLATINGby Trevor Davis at DCEERS on July ,
View Slide
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.@trevor_davisHI! I’MI work as a Front-End Developer at Viget.TREVOR DAVIS
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.I. StashII. Creating Simple PluginsWHAT WE WILL COVER
STASH
© 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 gapsSTASH
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission._layouts/base
{if {exp:stash:not_empty name="title"}}{exp:stash:get name="title"} |{/i }Site Name{exp:stash:get name="content"}
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.site/index
{embed="_layouts/base"}{exp:stash:set_value name="title" value="Homepage"}{exp:stash:set name="content"}Here is my content{/exp:stash:set}
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.RENDERED PAGE
Homepage |Site NameHere is my content
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.REAL EXAMPLE
© 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 bythat personVIGET.COM PROFILE PAGES
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.THE OLD WAY
{embed="structure/header"}{exp:channel:entrieschannel="profile"require_entry="yes"limit="1"}{title}{profile_job_title}{profile_bio}{embed="about/_blog_posts"}...{/exp:channel:entries}{embed="structure/footer"}
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.THE NEW WAY
{embed="_layouts/base"}{exp:stash:set parse_tags="yes"}{stash:blog_posts}{exp:channel:entrieschannel="blog"dynamic="no"username="{segment_3}"}{title}{stash:num_posts}{absolute_results}{/stash:num_posts}{/exp:channel:entries}{/stash:blog_posts}{/exp:stash:set}
{exp:channel:entrieschannel="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}
arrestedstills.tumblr.comCREDITSHOW I FELT AFTERLEARNING HOWTO USE STASH
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.SERIOUSLY,GIVE IT A TRY
CREATINGSIMPLE PLUGINS
© 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 pluginCREATING SIMPLE PLUGINS
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.SIMPLE EXAMPLE
echo urlencode('http://viget.com/blog/awesome-entry-title');?>
{exp:vl_client:url_encode}http://viget.com/blog/awesome-entry-title{/exp:vl_client:url_encode}
public function url_encode(){$tagdata = $this->EE->TMPL->tagdata;return urlencode(trim($tagdata));}
http%3A%2F%2Fviget.com%2Fblog%2Fawesome-entry-title
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.A MORECOMPLEX EXAMPLE
{exp:vl_client:entry_count channel_id="4"}
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;}}}
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.PKG.IO
© 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 methodsSITE SPECIFIC PLUGINS
© Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.Stash: devot-ee.com/add-ons/stashPkg.io: pkg.ioSample Plugin: gist.github.com/3191839web: trevordavis.nettwitter: @trevor_davisThanks!Let’s ConnectResources