mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Merge pull request #3902 from Chrisui/custom-tag-templates
Custom template files for custom tags
This commit is contained in:
commit
805f45900e
3 changed files with 54 additions and 1 deletions
|
@ -189,7 +189,7 @@ frontendControllers = {
|
|||
// Render the page of posts
|
||||
filters.doFilter('prePostsRender', page.posts).then(function (posts) {
|
||||
getActiveThemePaths().then(function (paths) {
|
||||
var view = paths.hasOwnProperty('tag.hbs') ? 'tag' : 'index',
|
||||
var view = template.getThemeViewForTag(paths, options.tag),
|
||||
|
||||
// Format data for template
|
||||
result = _.extend(formatPageResponse(posts, page), {
|
||||
|
|
|
@ -45,4 +45,25 @@ templates.getThemeViewForPost = function (themePaths, post) {
|
|||
return view;
|
||||
};
|
||||
|
||||
// Given a theme object and a tag slug this will return
|
||||
// which theme template page should be used.
|
||||
// If no default or custom tag template exists then 'index'
|
||||
// will be returned
|
||||
// If no custom tag template exists but a default does then
|
||||
// 'tag' will be returned
|
||||
// If given a tag slug and a custom tag template
|
||||
// exits it will return that view.
|
||||
templates.getThemeViewForTag = function (themePaths, tag) {
|
||||
var customTagView = 'tag-' + tag,
|
||||
view = 'tag';
|
||||
|
||||
if (themePaths.hasOwnProperty(customTagView + '.hbs')) {
|
||||
view = customTagView;
|
||||
} else if (!themePaths.hasOwnProperty('tag.hbs')) {
|
||||
view = 'index';
|
||||
}
|
||||
|
||||
return view;
|
||||
};
|
||||
|
||||
module.exports = templates;
|
|
@ -52,4 +52,36 @@ describe('Helpers Template', function () {
|
|||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getThemeViewForTag', function () {
|
||||
var themePathsWithTagViews = {
|
||||
'assets': null,
|
||||
'default.hbs': '/content/themes/casper/default.hbs',
|
||||
'index.hbs': '/content/themes/casper/index.hbs',
|
||||
'tag.hbs': '/content/themes/casper/tag.hbs',
|
||||
'tag-design.hbs': '/content/themes/casper/tag-about.hbs'
|
||||
},
|
||||
themePaths = {
|
||||
'assets': null,
|
||||
'default.hbs': '/content/themes/casper/default.hbs',
|
||||
'index.hbs': '/content/themes/casper/index.hbs'
|
||||
},
|
||||
TAG_CUSTOM_EXISTS = 'design',
|
||||
TAG_DEFAULT = 'development';
|
||||
|
||||
it('will return correct view for a tag', function () {
|
||||
var view = template.getThemeViewForTag(themePathsWithTagViews, TAG_CUSTOM_EXISTS);
|
||||
view.should.exist;
|
||||
view.should.eql('tag-design');
|
||||
|
||||
view = template.getThemeViewForTag(themePathsWithTagViews, TAG_DEFAULT);
|
||||
view.should.exist;
|
||||
view.should.eql('tag');
|
||||
|
||||
view = template.getThemeViewForTag(themePaths, TAG_DEFAULT);
|
||||
view.should.exist;
|
||||
view.should.eql('index');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue