From e107 Wiki
Jump to: navigation, search

e107 Wiki: English | Русский | Deutsch | Français | Magyar | Português | Български | Česky | Nederlands | Ελληνικά | Italiano | Norske | Polska | Slovenščina | Español | Svenska | Translate: Wiki | Page


Current Release 1.0.4 | | Download | Changelog | Forum | Plugins | Themes | RSS Feed of Latest Changes | Atom Feed of Latest Changes

e107 Shortcode Guide
Main page > I : First Aid > II : Development > III : Administration > IV : How To's > V : Plugin Writing > VI : Theming & Shortcodes

Formatting Shortcodes

You may find the need to add formatting around a shortcode depending on the shortcode content.

This is now possible with the $sc_style array.


For example, you may want to show a user avatar inside a DIV. If the user does not have an avatar configured, you don't even want the DIV to appear.

In your theme.php you would add something like:

Code: theme.php snippet
$sc_style['AVATAR']['pre'] = "<div class='myclass'>";
$sc_style['AVATAR']['post'] = "</div>"; 

When the shortcode engine renders the {AVATAR} shortcode, it will attach the 'pre' and 'post' strings to the return value only if it has some content (i.e. is not an empty string).

Template Shortcoding

For templates such as the content management and forum plugins you may wish to add shortcodes to a shortcode.php file. In these instances you will have to declare the shortcodes as a Global Variable within the shortcode.php file to use formatting.

Template Shortcoding Example

Suppose you want to add a simple shortcode to the content management application that returns an integer ID of the content parent category within the content_content template. This is a silly example because the shortcode will always return a value, but it nonetheless illustrates the formatting.

In content_shortcodes.php you would add something like:

Code: shortcode to return parent id
global $CONTENT_PARENT_ID, $row;
$CONTENT_PARENT_ID = intval($row['content_parent']);

You should now be able to add formatting to {CONTENT_PARENT_ID} in your template.