Customize tags with Low Variables

In this second example on how to use Low Variables to your advantage, I’ll show you how to use it to control your ExpressionEngine tags. In this case, it will result in a customizable home page, where you can change the type and number of articles shown, whether to show a sidebar or not and the ability to edit bits of text otherwise hardcoded in your templates.

Sandbox site

Let’s take a look at the current home page of the sandbox site. There’s a heading that reads “Latest news”. Below that are two articles. There’s also a sidebar with some contact information. In order to customize the home page, we’ll need to add a couple of variables. Here’s what I added:

  • {low_home_heading}: to edit the heading. Variable type: Text Input.
  • {low_home_categories}: so the user can select categories from which to pull entries. Variable type: Select Categories (see image below).
  • {low_home_status}: so the user can select the statuses of entries to show. Variable type: Checkbox group.
  • {low_home_limit}: so the user can select how many entries are shown on the home page. Variable type: Radio group.
  • {low_home_no_results}: the message shown if no entries match the given criteria. Variable type: Textarea.
  • {low_home_sidebar}: option to show or hide the sidebar. Variable type: Checkbox.

Edit Variable screen Low Variables home screen, group Home

{low_home_heading} and {low_home_no_results} do not need early parsing to be enabled, but the others do. They are used as input for the {exp:weblog:entries} tag in the template. {low_home_sidebar} is used as a global conditional. Here’s how the template might look:

<div id="content">

	<div id="primary">
		<h2>{low_home_heading}</h2>
		{exp:weblog:entries category="{low_home_categories}" status="{low_home_status}" limit="{low_home_limit}"}
			<div class="article">
				<h3>{title}</h3>
				{body}
			</div>
			{if no_results}
				<p>{low_home_no_results}</p>
			{/if}
		{/exp:weblog:entries}
	</div>

	{if low_home_sidebar == 'y'}
	<div id="aside">
		<!-- Sidebar here -->
	</div>
	{/if}

</div>

There you go! You can use Low Variables to customize your template tags without the heartache!

January 14th 2010 | Add-Ons, ExpressionEngine, Low Variables

Leave a comment



Some html (a, em, strong, etc) allowed.
Email won’t be displayed and takes care of your Gravatar.