How do I find the View template for a Page (Document)?

I'm looking for the .pt template file... I'm new to Plone and have never had to edit something like this, but I need to make some changes. Where do I find this .pt file? I read through the documentation and it's no help! Thanks,

OK, but where is that file exactly on my server? Talk to me like I'm a dumb-dumb

I mean, I did a

find -name "*.pt" -type f

and it came back with no results. I was in the /opt/plone/zeocluster folder

I did also try the /opt/plone folder and I found this file:

/buildout-cache/eggs/plone.app.contenttypes-2.1.10-py3.8.egg/plone/app/contenttypes/browser/templates/document.pt

However, it seems to be in a cache folder (buildout-cache) so I'm not sure if I'm supposed to edit it.

It works but it is not the way it is supposed to work. You can start reading this:

you can customize something TTW, if you go to /portal_view_customizations/manage_workspace but it is not recommended.

I'm using Plone 5, would those directions be the same?

basically yes on customizing templates. Theming is different.

A view does not neccessarily have to be a .pt-template. Often a view is a combination of .py (the logic) and a .pt file. Sometimes one use only one of them.

It is not a good idea to edit the view template. It will give you problems when upgrading etc. It is better to override it or make your own

If you just want to override 1, it might be better if you ask of that specific (one), and what you need to change.

Thanks @yurj that training site is helpful. I might have to start from the beginning since reading the docs is just way too advanced for me right now. I have no idea what they're talking about haha.

@espenmn thanks. Yeah I actually created a new content type using dexterity. With some added custom fields... they work great for data entry, but when published, those custom fields are not showing up on the end user view... so I just wanted to be able to add that in the template or view or something... it seems like it would be pretty easy to do (I've done it in other CMSses and stuff), but I guess it's more complicated in plone

Not sure about complicated when something as trivial as this gives you a nicely tabbed custom view of all your fields...

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
    xmlns:tal="http://xml.zope.org/namespaces/tal"
    xmlns:metal="http://xml.zope.org/namespaces/metal"
    xmlns:i18n="http://xml.zope.org/namespaces/i18n"
    metal:use-macro="context/@@main_template/macros/master"
    i18n:domain="plone">
<body>

<metal:content-core fill-slot="content-core">
        <form id="form" class="enableFormTabbing pat-autotoc autotabs"
              data-pat-autotoc="levels: legend; section: fieldset; className: autotabs">

          <fieldset id="form-groups-main-content">
            <legend i18n:translate="" >
              <span tal:omit-tag i18n:translate="">Main</span>
            </legend>
            
            <tal:block repeat="widget view/widgets/values" >
              <tal:widget tal:replace="structure widget/@@ploneform-render-widget"/>
            </tal:block>
          </fieldset> 

          <fieldset
                tal:define="groups view/groups;"
                tal:repeat="group groups" class="table"
                tal:attributes="id python:''.join((group.prefix, 'groups.', group.__name__)).replace('.', '-')"
          >
            <legend i18n:translate="" tal:content="group/label" />
            <tal:block tal:repeat="widget group/widgets/values">
                <tal:widget i18n:translate="" tal:condition="widget/value"
                                tal:replace="structure widget/@@ploneform-render-widget"/>
            </tal:block>
          </fieldset>
</metal:content-core>
</body>
</html>

I assume you made this TTW (in the control panel).

For views, it can be a good way to make them with plone_cli.

Unless your fields are 'special', you should be able to make one by:

  1. plonecli create addon src/my.addon

  2. cd my.addon

  3. plonecli add view

  4. In the view template.pt you add code similar to:

    <p>${context/somefieldname}</p>

If you dont need the python (logic) part, you can remove it (probably after you see that everything works)

Then you need to make sure your view 'works' with you content type.

  1. To test/try, you edit 'for' in configure.zcml ( change it to for="*" until you know everything works

  2. In http://yoursite/manage_main go go to 'portal_types' and add the name of the view to 'avable views' (you see the name in configure.zcml file). Probably, you also want to set it as 'default view'.

When everything works, you might want to change the for="*" setting to just your (new) content type.

PS: You also needs to add your add-on to plone:

  1. Put it in the src folder
  2. add it to the eggs section
  3. Add it to the 'develop section'
  4. Run bin/buildout
  5. Restart plone
  6. Install it from the control panel
1 Like

Wow @espenmn super appreciate the help, and that you broke it down into steps.. it really helps. However, I'm running into a problem because plonecli doesn't seem to be a command that it recognizes. The closest I can find is in the bin folder plonectl, but I know that's just for starting and stopping the server, so that can't be it... is it in a weird location or do I need to install it or something? I'm using Plone 5.2.2

Thanks!

You will need to install plonecli. It is very easy.

2 Likes