Create custom page template based on default for dexterity type - plone

I have created a page template for my custom dexterity type.
The default view automatically shows all the fields, rather than my custom template which shows no fields.
I'd like to start my template by copying the default template. I have tried pasting in a copy of plone.app.dexterity.browser/item.pt however that gives me
LocationError: (<my.types.resource.ResourceView object at 0xb4d18bcc>, 'widgets')
I am not sure why.
I guess that using this template might not even be the best solution, if I need to change the way individual fields render. In that case I am wondering how I can start with a template which contains the fields in my type (in the past I used ArchGenXML). Is there an equivalent process for dexterity?

Derive your view class from dexterity.DisplayForm.
This may make your copy/pasted template work immediately by giving it the view methods and properties it needs. It will also make available variable like view.widgets, which contains a list of display widgets in schema order.
See http://developer.plone.org/reference_manuals/external/plone.app.dexterity/custom-views.html#display-forms for details.

Related

Embedding the view of a url inside the header of another view

Currently, I have a dynamically created custom pie chart located at mywebsite.com/customchart that is created through a module I made using Highcharts.
I have view, that is listed in the views module shown in mywebsite.com/admin/structure/views/view/ which I would like to embed the custom chart into but I cannot find it through Add Header>Global: View area.
How exactly would one be able to achieve this? Programatically? How?
You can do it programmatically.
First you have to find out what template file is used for rendering the header. Easiest way: go editing your view, select proper display and then unfold "Advanced" options block on the right column and click "Theme: information". Here you can see what templates files are used (assuming you are using Drupal 7). The used ones are in bold. You can collect actual template code there so you don't have to find template file at all if you want to override it. And you can see file naming suggestions, so there you have everything you need to override template file.
If your theme is not overriding standard templates then you should do that - it's not good idea to change directly templates provided by Views module.
So, the first part would be finding out where would you like to embed the view, at what template and at what position. Second part is using function views_embed_view() for doing that:
https://api.drupal.org/api/views/views.module/function/views_embed_view/7.x-3.x
As you can see there, first parameter is machine name of the view, second of display and then you can pass parameters if your view accepts them. So call that function from proper place and you'll have your view embedded.
Also, there is display type "embed" which you can use for embedding views like this. It will provide those "edit view" links when you hover your view content while logged in as admin...

Drupal page content

I'm new to drupal and reading through docs, but hoping to get an explanation for something.
I have a page called page--type-home-page.tpl.php.
Part of this page prints render($page['content'])). I want to remove something that is rendered as part of the page content from the page, but don't understand where this comes from and where/how to look.
Thanks!
Assuming you're talking about Drupal-7
Well the $page['content'] contains a string, which is a rendered version of what's injected into the content region of your theme.
By default, the only block in this region is the "Main page content" block that is generated by the Drupal core. Many things can generate this content but it always pass through the menu API. For instance, if you're viewing a node, the URL used is: node/12. The node module declares a menu entry for node/%node, this menu entry contains a callback function that will render whatever the module wants to render. The module, then, may use different strategy to render it's content from a simple function to a complex imbrication of templates.
The key to alter what's in the box, sorry, what's in the $page['content'], is to know what is rendered and to understand how it's rendered.
If it's a node, first you want to look if you can achieve your goal through the display settings of the content type. admin/structure/types/manage/page/display: And this is true for all entities (users, comments, taxonomy term etc.) Because this is the first thing the module of these entities will put together when they'll try to render your content.
If this is not enough to achieve your goal, you can look into the module that renders the path to see if it hasn't a .tpl.php. You'll be able to re-use it in your theme. You'll want to copy/paste the file in your theme and edit it.
If the module do not have a tpl file to override, try a template suggestion: here's a list from Drupal.org
Ex: node--type.tpl.php
If all this doesn't satisfy your need, you'll have to dig into preprocess functions; Those functions allow you to modify what's in the variables passed to .tpl.php files. That's a little more advanced and I recommend you to read this previous stackoverflow question/answer
Simply, don't use that $page['content'] which prints all content, but place your custom template code instead and print separate field values where you need them like:
<?php print render($content['your_field_name']); ?>
https://drupal.stackexchange.com/questions/30063/how-to-print-fields-in-node-tpl-php
If you want to do just simple styling, like excluding some field you can use content type display options like mgadrat explained, but if you want to use some complex styling, with totally custom html this solution is easier.

Drupal Views2 Exposed Form

A while back you commented on a poster's question for how to alter the Drupal Views2 Exposed Form. In the post you mentioned:
The proper way of changing the theme would be to override the views-exposed-form.tpl file in your theme's folder. Bear in mind that this will apply to all exposed filter forms, to theme a specific one, you will need to use a different name for that filename, like:
views-exposed-form--TITLE--DISPLAY.tpl.php views-exposed-form--TITLE.tpl.php
and some others, you can check the Theme: Information section of your views for template naming conventions.
Can you expand on what the 'TITLE' and 'DISPLAY' are exactly? Are both template files needed or just one of them?
Thanks.
I am not the author of the post you are referring to, but I can answer this question.
The way Views theming works is that there is a base template for a specific part of the output and this base template can be made more specific by adding additional qualifiers to it.
If you copied /sites/all/modules/views/theme/views-exposed-form.tpl.php to your theme folder (or from wherever you have Views installed), made changes to the copy, and then edited your view and chose Theme: Information and clicked Rescan Template Files, Views would now use this template in your theme folder for rendering the exposed filters form. This is the base template name and so it will be used for every view's exposed filters form.
If the change you're making should be applied to every exposed filters form then you're done. However you probably want to limit this overriden template file to specific views or even specific displays of specific views. If you want to apply the template only to a view named testview then you could rename your theme's views-exposed-form.tpl.php to views-exposed-form--testview.tpl.php. Don't forget to use the Rescan Template Files button after each rename or new file. Now that template only applies to the view testview and all of its displays.
A view can have multiple displays - maybe a block, a page, a page for admins, etc. These are listed vertically down the left side of the edit page for a view. You can get more specific and target a particular display of a particular view. To do this, you might name this template file views-exposed-form--testview--page-1.tpl.php which would cause it only to be used for the testview view and only for the first page display of that view. You can find the display name by hovering over the tab - it will appear at the end of the URL your browser shows in the status (default, page_1, etc). Just remember to turn underscores to hyphens in the template filenames: use page-1 not page_1.
You can also target all pages for example: views-exposed-form--testview--page.tpl.php.
These naming conventions as well as a list of templates which can be overriden are available here: http://views.doc.logrus.com/ (click Views Template Files).
So, if you have a specific display or view where you want to override the default template then you only need a single file targeted for that combination. If you need to target additional views or display combinations, you will have more files.
You can try Views exposed form layout module for views exposed form theming.

Drupal6 - Display specific View from a specific user in page

I need a help displaying a specific View result in a page which the user created it.
story...
"User X has created a Page called My Store and UserX has products which was created in custom Content Item."
Now how do I show this UserX's products in his My Store page?
I have already made a view called User_Store_View, I added a Page Display and on Page Settings:Path, the value was "node/%".. now I guess my problem is on the Arguments?
The path should be something like my-store and it should have an argument of user id. Given your requirements I think setting the default behaviour for the argument being invalid or not being supplied to an empty result set would be the most sensible(I think the default is show all). That may be all you really need.
However, if your product is a type that you've created yourself you will need to do some behind the scenes wiring to expose all your fields to Views; it's almost always better to build a content type using CCK so it's already hooked up to Views. And D7 is a different beast in this regard, with fields part of core and whatnot, so I can't help you out there.

Customize the way CCK Node Reference fields are displayed in Drupal

Node reference fields in Drupal are displayed as lists by default. Is there a way to change that?
I'd like to output them as JSON so I can create a fancy JavaScript visualization.
You can modify it in 2 ways: via custom module with function hook_form_alter or via theming (preprocessing form or templating form).
http://api.drupal.org/api/function/hook_form_alter/6
http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6
For AHAH: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#ahah
Also, nodereference already have little ahah: "autocomplete" in field editing of custom node type.
Consider the Content Templates (Contemplate) module. Here is a quote about it (from the module's project page):
... allows modification of Drupal's teaser and body fields using administrator defined templates. These templates use PHP code and all of the node object variables are available for use in the template. An example node object is displayed and it is as simple as clicking on its properties to add them to the current template.
This module was written to solve a need with the Content Construction Kit (CCK), where it had a tendency toward outputting content in a not-very-pretty way. And as such, it dovetails nicely with CCK, adding a "template" tab to CCK content-type editing pages and pre-populating the templates with CCK's default layout. This makes it easy to rearrange fields, output different fields for teaser and body, remove the field title headers, output fields wrapped for use with tabs.module (part of JSTools), or anything you need.
But Content Template can actually be used on any node type and allows modification of the teaser and body properties before they go out in an RSS feed, search index, or are handed off to the theme. Additionally, ConTemplate can choose to add any files, images, or other media to RSS feeds as an attachment.
Templates are normally stored in the database but it is also possible to create disk-based templates which live in your sites directory and can be inherited across multisite installations in the same way as themes or modules.
Try the Custom Formatters module, simply make a custom formatter to render the node out exactly how you want it, then output the formatter to code or to a Feature for deployment.

Resources