Creating Views and Viewlets

I'm trying to create a new view here. I'm not able to render a certain template. I'm following the below given steps. I'd be glad if anyone could help me out as I would like to explore more as to how these views and viewlets work.

  1. I've created a new add-on by using the command mrbob mrbob:plonetheme.tango
  2. I've created a views.py file with the following code in it
    from zope.interface import Interface from Products.Five.browser import BrowserView from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
    class MyView(BrowserView):
    index = ViewPageTemplateFile("myview.pt")
    3.Then I've added a template myview.pt in /plonetheme/tango/browser/templates/myview.pt
    4.I've registered the template in browser/configure.zcml.
    Here is the code:
    `

<plone:static
name="plonetheme.tango"
type="plone"
directory="static"
/>

<browser:page
      for="*"
      name="test"
      permission="zope2.Public"
      class=".views.MyView"
      />
` Here is the HTML for myview.pt: `
<metal:block fill-slot="content-core">
        XXX - this text comes below title and description
</metal:block>
` When I go to this site,

https://localhost/Plone/@@myview
It says that the page does not exist.
Don't know where I'm going wrong. I would appreciate it if you could help me out.

See GSoC 2018 Ideas: Improve plonecli and bobtemplates.plone

Your view is registered for „test“, not for „myview“.

In case you dont need any logic or if you just want to configure it in zcml:

<browser:page
  for="*"
  name="test"
  permission="zope2.Public"
  template="mytemplate.pt" 

The template would usually be something like

< 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"
  lang="en"
  metal:use-macro="context/main_template/macros/master"
  i18n:domain="your.addon">

    <body>
        <metal:main fill-slot="content-core">

If you wand to drop the title and description, use something like:

  <metal:main fill-slot="content">

Thanks for the pointers! Now, I have all of this inside an add-on. I've mentioned in the buildout.cfg under the [eggs] section. When I try to update buildout by using the command bin/buildout on the command line I get such an error:
Setting socket time out to 3 seconds. While: Installing. Getting section mrbob. Initializing section mrbob. Getting option mrbob:backups-dir. Error: Referenced option does not exist: buildout var-dir
What might be the prominent issue?

What could be a possible alternative to register the plone add-on ?
Because when I navigate to this url http://localhost/Plone/@@test
I get the following error:

This page does not seem to exist.

Nobody can your problem without the real code...put it on Github.

1 Like

I would appreciate the feedback I would receive for my code as it would be helpful in my further development of views and viewlets.

I am a bit confused here:

Are you 'just trying to add some views and viewlets' or are you working with (improving) bobtemplates?

Bobtemplates is used for 'making stuff without coding too much', but after you have used it to make your theme, your add-on (etc) you dont need to think about it anymore.

After that, you should have an add on that you can put in your 'src' folder and add it to the 'eggs' and 'src' sections of your buildout.

Also: I dont think you want to call you add-on 'plonetheme.tango' (as an add on with this name already exists, so you might want to change the name to 'plonetheme.mytheme' ?

You will not receive feedback for code that does not exist for us.
Put it into a repo and share it...that‘s how it works.

-aj

I'm trying to help improve bobtemplates.plone (referring to one of the gsoc ideas) .As a primer, I'm trying to explore how to create views and browserviews and get acquainted with their practices.
And yes, I will surely change the name for the add-on.
Can you guide me in contributing for the idea ? What would be steps involved in integrating missing templates such as view,viewlets,portlets,tiles etc.. into bobtemplates? I would be glad if you could help me out.

I think this would be useful.I've created an add-on and put some sample views and logic to test it out.