hypejunction/elgg-snippets

Editable HTML snippets for use in themes and views

Installs: 23

Dependents: 0

Suggesters: 0

Stars: 1

Watchers: 1

Forks: 1

Type:elgg-plugin

1.0.1 2019-07-30 11:11 UTC

README

Elgg 2.3

Reusable and editable snippets with variable interpolation

Features

Using plugin settings to alter large chunks of HTML is repetitive and not very efficient: you have to update plugins settings, remember in which plugin a setting lives, figure out how to populate default values, implement weird mechanics to interpolate variables etc.

This plugin makes it easy, just create a snippets in your views and will be available for editing via admin interface. Snippets can then be injected into your views with elgg_snippet().

Usage

Once the plugin is enabled, snippets can be edited under Admin > Appearance > HTML Snippets.

Create a default snippet as a .twig view anywhere in views/default/snippets/:

// my-plugin/views/default/snippets/page/footer.twig
<div class="footer">
  <a class="{{ normalizeUrl('/contact') }}">Contact Us</a>
</div>

Render a snippet where it belongs:

// my-plugin/views/default/somewhere.php
echo elgg_snippet('page/footer');

You can provide the title and the description of the snippet using translations:

// languages/en.php
return [
   'snippet:page/footer' => 'Page Footer Template',
   'snippet:page/footer:help' => 'Displayed on all pages in the footer area',
];

Storage

Snippet overrides are stored in the dataroot, so be sure to copy them over if migrating your site. You can also reset to default template, by deleting a corresponding snippet from the dataroot.