Skip to content

Instantly share code, notes, and snippets.

@rsanchez
Created June 21, 2012 20:21
Show Gist options
  • Save rsanchez/2968310 to your computer and use it in GitHub Desktop.
Save rsanchez/2968310 to your computer and use it in GitHub Desktop.
Using stash to move safecracker JS to footer
{exp:safecracker channel="foo" include_jquery="no"}
{exp:stash:set name="safecracker_head"}
{safecracker_head}
{/exp:stash:set}
......
{/exp:safecracker}
......
<script type="text/javascript" src="/js/jquery.min.js"></script>
{exp:nest parse="inward"}
{exp:stash:get name="safecracker_head"}
{/exp:nest}
</body>
</html>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$plugin_info = array(
'pi_name' => 'Nest',
'pi_version' => '1.0.0',
'pi_author' => 'Rob Sanchez',
'pi_author_url' => 'http://github.com/rsanchez',
'pi_description' => 'Useful when you need to delay the parsing of the inner, nested tag.',
'pi_usage' => '{exp:nest parse="inward"}
{exp:other:tag}
{/exp:nest}',
);
class Nest
{
public $return_data = '';
public function Nest()
{
$this->EE =& get_instance();
return $this->return_data = $this->EE->TMPL->tagdata;
}
}
@rsanchez
Copy link
Author

I originally had this without the Nest plugin. But without it the stash:get in the footer was getting called before the stash:set nested in safecracker. Wrapping this dead-simple exp:nest plugin around it made everything parse in the right order.

@GDmac
Copy link

GDmac commented Jun 26, 2012

That nest plugin is a nice solution for the ee-toolbox, especially when using a single template to generate a webpage.

Currently i'm working a lot with a basic html-layout which is embeded (e.g. called late) and where all the stash vars are 'get'. When generating the page you can append or prepend the output to the various parts of the page. e.g. to page_sidebar, main_content, head_css, page_breadcrumbs etc.

{!-- contact/index --}
{embed="page_layouts/basic_layout}
{exp:stash:set name=page_title ...
{exp:stash:append name="main_content" ...
{exp:stash:set ....

{!-- page_layouts/basic_layout --}
<html>
<title>{exp:stash:get name=page_title ...
{exp:stash:get name=head_js ...
<body>
<div class=col9>{exp:stash:get name=main_content ...
<div class=col3>{exp:stash:get name=page_sidebar ...

@rsanchez
Copy link
Author

Actually, with the latest from the dev Stash branch you can do this without the nest plugin:

{exp:stash:get name="safecracker_head" process="end"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment