Advanced Template Tags

From Shopp Documentation

Jump to: navigation, search
This document is aimed at experienced developers interested in more advanced ways of customizing Shopp templates. The instructions provided here assumes the developer has a moderate amount of programming experience with PHP, HTML and CSS.

Returning Tag Results

By default, shopp() tags output results directly into your template as HTML markup. However, in some cases you may want the output of a shopp() tag returned as PHP data that can be saved in a variable for further processing, reprocessing or filtering. You can use the return option to do it. In the options parameter of any shopp() tag, simply add return=true to get the results back as data. For example, you might want to get your store's category list for processing:

<?php
$categories = shopp('catalog','category-list','return=true');
?>

A more practical example of where this comes in handy would be stripping the (0) off of categories that have no products when showing a category list that includes the number of products per category. Here's how it's done:

<?php
$categories = shopp('catalog','category-list','products=on&return=true');
$categories = str_replace('(0)','',$categories);
echo $categories;
?>

Boolean Option Values

When specifying boolean options on any shopp() tag, you can use a number of positive and negative keywords:

  • true or false
  • yes or no
  • on or off
  • 1 or 0

This can be useful for testing certain conditions using a PHP if statement.