Please note that Form2Content is no longer being developed. All files from the latest version can be found on Github.

Form2Content Forum

Questions and answers for Form2Content, a Joomla CCK.
  1. Hans de Jong
  2. F2C article templating
  3. Saturday, 08 December 2018
  4.  Subscribe via email
I would like to calculate the age from a given birthdate. I found these examples, but I'm not sure how to implement them in an article template.

Convert date to age
Calculate Age

Any help appreciated
Accepted Answer
Accepted Answer Pending Moderation
Hi there Julien,

I searched in the Joomla extension directory, and found the
Age of plugin.

It can do more then I need, but it is fine for my purposes. I added the following lines in the f2c article template:
{if $BIRTHDATE}
She is {ldelim}ageof{rdelim}{$BIRTHDATE}{ldelim}/ageof{rdelim} years old.
{/if}

The Joomla article at the backend contains the line (example):
She is {ageof}11-10-2005{/ageof} years old.

On the website you can read:
She is 13 years years old.


Thanks for your help again! :)
Responses (4)
Accepted Answer Pending Moderation
Hi Hans,

Yes, you can create your own Smarty functions in PHP that can do things, like calculate an age from a birthdate.
The functions are called modifiers and are store in the directory <your website root>/components/com_form2content/libraries/smarty/plugins

One of those modifiers for example is the file smarty_modifier_contains.php
You can create your own modifiers and place them in this directory, you can then use them from Smarty.

But: When a template is rendered the html is generated static into the content table, which means that the modifier will only fire, when you create or modify an F2C article.

Since an age can vary from day to day, I don't think you want it 'hard-coded' in the template, since it will never get updated while time goes on.

A better way to solve this problem is to write a Joomla (not F2C!) plug-in that will dynamically calculate the age every time the article gets rendered.

best,
Julien
  1. more than a month ago
  2. F2C article templating
  3. # 1
Accepted Answer Pending Moderation
Hi there Julien,

I searched in the Joomla extension directory, and found the
Age of plugin.

It can do more then I need, but it is fine for my purposes. I added the following lines in the f2c article template:
{if $BIRTHDATE}
She is {ldelim}ageof{rdelim}{$BIRTHDATE}{ldelim}/ageof{rdelim} years old.
{/if}

The Joomla article at the backend contains the line (example):
She is {ageof}11-10-2005{/ageof} years old.

On the website you can read:
She is 13 years years old.


Thanks for your help again! :)
  1. more than a month ago
  2. F2C article templating
  3. # 2
Accepted Answer Pending Moderation
Hi Hans,

Good to hear that you have found a working solution! Thanks for sharing the result.

best,
Julien
  1. more than a month ago
  2. F2C article templating
  3. # 3
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.