We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Formatted Date

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.

Hi,

I have rewritten Lodewijk Schutte’s Nice Date plugin. The result is Formatted Date plugin.

The difference from original plugin is possibility to set global values for “format” and “localize” parameters which allows to use these parameters only in cases when global values need to be overridden.

PARAMETERS

1) date - Required. Allows you to specify a date. Use the same format as in Control Panel’s Publish page.

2) format - Optional. Allows you to specify how date should be formatted. About date formatting see here.

In case no global format is set format parameter must be defined.

3) localize - Optional. Allows you to specify if the date should be localized. Possible values are “yes” and “no”. Default is “no”.

4) site - Optional. Allows you to specify site id. Default value is “1”.

SETTING GLOBAL VALUES

I. On top of plugin’s code you can find plugin’s config. Editing config you can change the names of global variables used to set global values for “format” and “localize” parameters. Default names of global variables are “global_date_format” and “global_date_localize”:

// Here you can define names of global variables
$date_format_globalvar = 'global_date_format';
$date_localize_globalvar = 'global_date_localize';

II. You can set global values for “format” and “localize” parameters

1) by setting values to $default_format and $default_localize variables in plugin’s config:

// Here you can define default format for dates
$default_format = '%F %j%S, %Y';
$default_localize = 'yes';

or

2) by defining global variables inside path.php file. To do this enter the lines as these inside path.php:

$global_vars = array(
"global_date_format" => "%F %j%S, %Y",
"global_date_localize" => 'yes'
);

or

3) by defining global template variables CP Home > Templates > Global Variables

Setting global variables inside path.php file has one advantage over setting values for $default_format and $default_localize variables on top this plugin’s code - you can use these variables not only with Formatted Date plugin but also together with other tags and variables. For example, if you have global_date_format variable specified in path.php then you can write such code:

{current_time format="{global_date_format}"}

Preference order of “format” and “localize” parameters, $default_format and $default_localize variables and global variables is as follows:

1) plugin reads value of “format” or “localize” paramer and uses it in case it is specified;

2) if there is no such parameter, then the plugin uses the value of “default_format” or “default_localize” variable if it is not equal to empty string;

3) if the value of “default_format” or “default_localize” variable is equal to empty string, then plugin finds if there is global template variables and uses their values;

4) if their are no global template variables then the plugin finds if there is global variables specified in path.php file and uses their values.

USAGE

In case no global value for format and localize are specified or global values for format and localize need to be overridden:

{exp:fdate date="2008-10-07" format="%F %j%S, %Y" localize="yes"}

In case global values for format and localize are specified:

{exp:fdate date="2008-10-07"}

Using the tag together with URL segment variables:

{exp:fdate date="{segment_3}-{segment_4}-01"}

Changelog:

-1.0 // Initial release -1.1 // added “site” parameter; added possibility to set global values for “format” and “localize” parameters in user-defined global template variables; added possibility to set names of global variables by editing plugin’s config.

       
Oxygen Smith's avatar
Oxygen Smith
120 posts
16 years ago
Oxygen Smith's avatar Oxygen Smith

Hey! This suited my purposes perfectly just for this one particular case - for parsing segment variables created by the calendar tag, and when there’s no results:

{if no_results}
    <div class="entry">
        Nothing's been entered on the calendar yet for
        {if segment_5 == ""}{exp:fdate date="{segment_3}-{segment_4}-01" format="%F %Y" localize="no"}.{/if}
        {if segment_5 != ""}{exp:fdate date="{segment_3}-{segment_4}-{segment_5}" format="%F %j%S, %Y" localize="no"}.{/if}
        
    </div>
{/if}

Thanks for writing it!

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I have released a version 1.1 of Formatted Date plugin.

In this release:

1) added “site” parameter;

2) added possibility to set global values for “format” and “localize” parameters in user-defined global template variables;

3) added possibility to set names of global variables by editing plugin’s config.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.