4 Quick Pligg Tips and Tricks

I have been working with Pligg for over four years now, and during that time I have collected several useful snippets of code that I found found to be quite useful when designing a Pligg template. This article includes some of those snippets, as well as some general tips for using Pligg CMS.

1. Smarty Modifiers and Functions

Here is another great feature that has been improved with the 1.0.2 release. We have recently added new Smarty modifiers and functions that allow you to alter variable output values. Many, but not all, of these modifiers have been documented by Smarty and Template Lite. Below are some examples of how you could use these Smarty modifiers to alter story content in link_summary.tpl.

Replace one word with another

The replace modifier is perhaps my favorite Smarty modifier because it can do a lot of fun things. Keep in mind that it does literal searches when finding terms to replace, so any difference in capitalization will be ignored.

Input:I just wanted to say hello.
Output:I just wanted to say howdy.

Next is an example of using 2 replace modifiers on the same variable. This example should be enough for you to figure out how to combine 2 or more modifiers to effect a single variable.

{$story_content|replace:’hello’:’howdy’|replace:’just wanted’:’love’}
Input:I just wanted to say hello.
Output:I love to say howdy.

Count the number of characters used

This will tally the number of characters used in a variable, including whitespace.


Truncate the story after 30 characters

This snippet will round the content to the nearest full word, making the output equal to or less than 30 characters every time. There are a variety of ways to use the truncate modifier, demonstrated on Smarty.net.


Capitalize each word

This will capitalize the first letter of every word.


Uppercase each word

Does exactly what you think it would, capitalizes every letter of every word.


Do some math

Not something that I have used in the past, but someone might find this useful.

{math equation=”(( x + y ) / z )” x=2 y=10 z=2 }

2. Check if a Module is Enabled

This next code snippet is an example of how you can check if a module is enabled or not from your template. If you design template that depends on a module, you can display an error message letting them know that they need to enable that module.

{if check_for_enabled_module(‘auto_update’,1)}      <!– Auto Update Module is enabled –> {else}      You need to enable the Auto Update module! {/if}

3. Module Language Translations

Lets say for example that you have a Russian Pligg site, where under Admin > Configure > Misc > Language you have set your site’s language to “russian”. This will not only change the main Pligg language file to Russian (/languages/lang_russian.conf), but it will also check for modules that have a Russian language file.

Many modules come with a lang.conf file, located in the module’s directory. This file defines the language variables used in the module, making it simple to change all of the words used by the module since they are contained in just 1 file. Modules will scan for a localized version of this language file before defaulting to a lang.conf file. For example if you have set your site language as “russian”, modules will try to load a lang_russian.conf file from the module directory before trying to use lang.conf.

4. Month, Day, Year, and Time Timestamps

Previous to 1.0.2, there was no simple method to print the submission time and date without using a two-line snippet of PHP in a template. The default setting would display X number of days ago that the story was submitted. The 1.0.2 release makes it much easier to insert a more standard timestamp on the story by letting you replace:

{$link_submit_timeago} {#PLIGG_Visual_Comment_Ago#}

With this:


This new variable will generate a date like “November, 12 2009 12:34 PM”. Similarly, you can display a more useful comment date by inserting the code {$comment_date} in the comment_show.tpl template file.

Share this post