diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index 262f614403..c28ecd756b 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -298,6 +298,10 @@ coreHelpers.content = function (options) { return new hbs.handlebars.SafeString(this.html); }; +coreHelpers.title = function () { + return new hbs.handlebars.SafeString(hbs.handlebars.Utils.escapeExpression(this.title || '')); +}; + // ### Excerpt Helper // // *Usage example:* @@ -787,6 +791,8 @@ registerHelpers = function (adminHbs, assetHash) { registerThemeHelper('content', coreHelpers.content); + registerThemeHelper('title', coreHelpers.title); + registerThemeHelper('date', coreHelpers.date); registerThemeHelper('encode', coreHelpers.encode); diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js index 82760535d0..3c3ad49d4d 100644 --- a/core/test/unit/server_helpers_index_spec.js +++ b/core/test/unit/server_helpers_index_spec.js @@ -169,6 +169,38 @@ describe('Core Helpers', function () { }); }); + describe('Title Helper', function () { + it('has loaded title helper', function () { + should.exist(handlebars.helpers.title); + }); + + it('can render title', function () { + var title = 'Hello World', + rendered = helpers.title.call({title: title}); + + should.exist(rendered); + rendered.string.should.equal(title); + }); + + it('escapes correctly', function () { + var rendered = helpers.title.call({'title': '