diff --git a/application/Espo/Core/Htmlizer/Htmlizer.php b/application/Espo/Core/Htmlizer/Htmlizer.php
index 055550cba2..1f7d78aff9 100644
--- a/application/Espo/Core/Htmlizer/Htmlizer.php
+++ b/application/Espo/Core/Htmlizer/Htmlizer.php
@@ -260,13 +260,20 @@ class Htmlizer
$data = $this->getDataFromEntity($entity, $skipLinks);
+ if (!array_key_exists('today', $data)) {
+ $data['today'] = $this->dateTime->getTodayString();
+ }
+
+ if (!array_key_exists('now', $data)) {
+ $data['now'] = $this->dateTime->getNowString();
+ }
+
foreach ($additionalData as $k => $value) {
$data[$k] = $value;
}
$html = $renderer($data);
-
$html = str_replace('?entryPoint=attachment&', '?entryPoint=attachment&', $html);
if ($this->getEntityManager()) {
diff --git a/application/Espo/Core/Utils/DateTime.php b/application/Espo/Core/Utils/DateTime.php
index 71ee463539..fd17d1e7a8 100644
--- a/application/Espo/Core/Utils/DateTime.php
+++ b/application/Espo/Core/Utils/DateTime.php
@@ -189,4 +189,38 @@ class DateTime
{
return date($this->getInternalDateFormat());
}
+
+ public function getTodayString($timezone = null)
+ {
+ if ($timezone) {
+ $timezoneObj = new \DateTimeZone($timezone);
+ } else {
+ $timezoneObj = $this->timezone;
+ }
+
+ $dateTime = new \DateTime();
+ $dateTime->setTimezone($timezoneObj);
+
+ return $dateTime->format($this->getPhpDateFormat());
+ }
+
+ public function getNowString($timezone = null, $format = null)
+ {
+ if ($timezone) {
+ $timezoneObj = new \DateTimeZone($timezone);
+ } else {
+ $timezoneObj = $this->timezone;
+ }
+
+ $dateTime = new \DateTime();
+ $dateTime->setTimezone($timezoneObj);
+
+ if ($format) {
+ $phpFormat = $this->convertFormatToPhp($format);
+ } else {
+ $phpFormat = $this->getPhpDateTimeFormat();
+ }
+
+ return $dateTime->format($phpFormat);
+ }
}
diff --git a/application/Espo/Resources/i18n/en_US/Template.json b/application/Espo/Resources/i18n/en_US/Template.json
index 2dcdfa8ef8..f47defea3e 100644
--- a/application/Espo/Resources/i18n/en_US/Template.json
+++ b/application/Espo/Resources/i18n/en_US/Template.json
@@ -24,6 +24,10 @@
"pageOrientation": {
"Portrait": "Portrait",
"Landscape": "Landscape"
+ },
+ "placeholders": {
+ "today": "Today (date)",
+ "now": "Now (date-time)"
}
},
"tooltips": {
diff --git a/client/src/views/template/fields/variables.js b/client/src/views/template/fields/variables.js
index f1323d129d..b2b7e8d025 100644
--- a/client/src/views/template/fields/variables.js
+++ b/client/src/views/template/fields/variables.js
@@ -86,12 +86,15 @@ Espo.define('views/template/fields/variables', 'views/fields/base', function (De
this.attributeList = attributeList;
- attributeList.unshift('');
+ if (!~this.attributeList.indexOf('now')) {
+ this.attributeList.unshift('now');
+ }
- this.translatedOptions = {};
- attributeList.forEach(function (item) {
- this.translatedOptions[item] = this.translate(item, 'fields', entityType);
- }, this);
+ if (!~this.attributeList.indexOf('today')) {
+ this.attributeList.unshift('today');
+ }
+
+ attributeList.unshift('');
var links = this.getMetadata().get('entityDefs.' + entityType + '.links') || {};
@@ -135,6 +138,12 @@ Espo.define('views/template/fields/variables', 'views/fields/base', function (De
var entityType = this.model.get('entityType');
this.attributeList.forEach(function (item) {
+ if (~['today', 'now'].indexOf(item)) {
+ if (!this.getMetadata().get(['entityDefs', entityType, 'fields', item])) {
+ this.translatedOptions[item] = this.getLanguage().translateOption(item, 'placeholders', 'Template');
+ return;
+ }
+ }
var field = item;
var scope = entityType;
var isForeign = false;