2.8.
Adding a custom view to the skin
Up one level
To provide a custom view for your content type, add a page template called 'instantmessage_view.pt' in the 'skins/instantmessage' directory with the following code:
<html metal:use-macro="here/main_template/macros/master"
i18n:domain="plone" >
<body>
<div metal:fill-slot="main"
tal:define="priority here/getPriority;
priority_color python:test(priority == 'high', 'red', priority == 'low', 'green', '')" >
<h1 tal:content="context/Title"
tal:attributes="style string:color:$priority_color" >
Title
</h1>
<p tal:content="structure here/getBody" />
<div class="documentByLine">
Message by <span tal:content="context/Creator" />
with <strong tal:content="priority" /> priority.
-
<span tal:replace="python:here.toLocalizedTime(context.CreationDate(),long_format=1)" />
</div>
</div>
</body>
</html>
After the product installation step, which we still have to discuss (see later), Plone should be able to find this template and use it as the content object's default view when you invoke the content's URL.
Python notes:
-
The new methods we use on the content object (getPriority, getBody, etc), called the "accessors", are generated by Archetypes as part of its internal mechanisms, based on the field definition in the content schema ; so if the field is called 'priority', there is a generated method called 'getPriority' responsible to return the stored value on the object. Note that the code of the method is not available somewhere for modification ; "generated" here means it is available in the server's memory, within Archetypes engine's registries, when the Zope server has started.