Get which template was selected to a content


#1

Enonic version: 7.1.1
OS: Ubuntu 19

I want to know which template was selected to a content via service, in Enonic 6.14.3 it was possible via page.template but it doesn’t seem to return anything in 7.1.1, any ideas?


#2

It’s still page.template (see results of lib-content.get() below). If you don’t have template inside page object it means that your page is either customised or using automatic template.

15:58:52.368 INFO  com.enonic.app.features - (/site/parts/getContent/getContent.js) Get result: {
    "_id": "251e6b26-5d9d-4337-981c-bc440e4076aa",
    "_name": "superhero",
    "_path": "/superhero",
    "creator": "user:system:su",
    "modifier": "user:system:ase",
    "createdTime": "2015-02-27T23:46:39.186Z",
    "modifiedTime": "2019-11-18T14:54:28.119340Z",
    "owner": "user:system:su",
    "type": "portal:site",
    "displayName": "Superhero",
    "hasChildren": true,
    "language": "en",
    "valid": true,
    "childOrder": "modifiedtime DESC",
    "data": {
        "description": "Blog application for Enonic XPwwww",
        "siteConfig": {
            "applicationKey": "com.enonic.app.superhero",
            "config": {
                "numPosts": "5",
                "commentSort": "ASC",
                "postsFolder": "64f66a5c-b933-410c-a24c-a1192b4a0c49",
                "postsList": "251e6b26-5d9d-4337-981c-bc440e4076aa",
                "searchPage": "45939e50-afb5-4f02-9fee-66489c74475e",
                "footerText": "<p><a title=\"Fastest way from idea to digital experience.\" href=\"https://enonic.com/\" target=\"_blank\">Proudly powered by Enonic XP</a><span class=\"sep\"> | </span>Theme: Superhero by <a href=\"https://wordpress.com/themes/\" target=\"_blank\">WordPress.com</a>.</p>",
                "loginPage": "75f6f354-491d-4102-a2e8-843270b63f23",
                "noLogin": false
            }
        }
    },
    "x": {},
    "page": {
        "type": "page",
        "path": "/",
        "template": "52514ac0-29a3-4775-b62a-e43db6696343"
    },
    "attachments": {},
    "publish": {}
}

#3

I see and I’m using automatic template. But, in case I change from automatic to another template, shouldn’t I be able to see it in Content Viewer?


#4

Content Viewer shows what is stored in the content. Template is stored in the content only when it’s using fixed template. In case of automatic template the system always finds the newest template matching the content type. In this case template is not stored in the content.

If you will change from automatic to fixed then you will see it in the Content Viewer, yes. You can also check what kind of template is used by the content inside its Details widget:


#5

Thanks a lot. So, if I do the following query “_path LIKE ‘/content/mysite/’ AND ngram(‘page.template’, '’, ‘OR’)” and it doesn’t return me any result, then can I say that there is no content with fixed template?

By the way, the content still store value for page.controller?


#6

page.controller was renamed to page.descriptor in XP7. Note that page can either have descriptor or template, not both at the same time.


#7