Customize the way CCK Node Reference fields are displayed in Drupal - 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.

Related

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 7: Add view to content type

I've been making a template for a particular content type, but just ran into a problem: I need to embed a view into the content type.
I am aware this can be done via several different methods, but I don't see one that fits exactly my needs:
I need the view added automatically for all pages of that content type.
Using blocks in a region is not an option, as I want to avoid defining a region in the middle of a page that should only be available for a specific content type.
Translatable label.
Possibility to freely apply a template to all fields in the content type (excluding the embedded view).
I tried doing it via page layout (Panels) and simply adding node content fields and the view to my layout regions, but then I get another problem: I can't style my content fields without doing something that seems a bit over the top:
Currently I have about 20 different content fields in the content type that are wrapped in HTML and styled in my template file. I have a translated label for each of these in the template file. From what I can tell I'd have to add a template for each of the panes containing content fields to add my translated labels and HTML needed to style each field.
I'm not really fond of making 20 templates, 20 theme hook suggestions to get the templates to work and 20 regions in the panel layout just to get a view inserted in the content type.
Am I doing something terribly wrong here? Any suggestions?
You may want to try the Viewfield module or similar modules (search for "view field" or "view reference").
If you are doing something more complex like changing/filtering the view based on some value in your content type, then you may have to use Viewfield module in combination with something else that will help fill in the filter values.
I've never done something like this before so I'm not sure exactly what module combination would work but Rules or Computed Field come to mind as possible helpers.
You have to use "views node field" http://drupal.org/project/viewsnodefield, after installing this module you have to select the "Node content" in the display (like blocks,page). then click the add display. if you want to display the content like this page http://www.richtown.ae/?q=content/arabian-ranches then you have to download the views_galleriffic module and install it and choose the style option "Galleriffic Gallery". You can choose the content type by using the filter in the views.
That's it cheers
i implemented this in my website richtown.ae
if you still unclear please send me the email social#richtown.ae i will reply you & ready to help you we can share information
i am using this module in drupal 6.
I resorted to using the EVA module ( http://drupal.org/project/eva ).
In addition to Woodgnome's answer
Let's say you have a content type named 'Product'
You want to attach a view to it.
Here are the steps using the eva module :
On your view edit page :
Section Displays
+Add : Eva field
Section ENTITY CONTENT SETTINGS
Entity type:Node
Bundles:Product
That's it, going to a node product type will now display the view

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.

drupal translate module issue, assign custom fields to autotranslate

Drupal:Can I assign custom fields to autotranslate them when I create a new article?
By default it creates and translates the Title and Body field, but I have several more depending on the content types. (This is set on actions)
I didn't quite know how to add more fields to translate
I am not exactly sure what those other fields are. Would the be something that is created using CCK or views?
Drupal uses the function t(...) to translate strings, if you want that functionality you need to wrap your text in that.
More info about t() and how it works. (Drupal 6)
More info about the Localization API (PDF cheat sheet)
UPDATE
Just found a link to what might be more suitable for your needs:
Drupal.org > Translating Content in Drupal

Theming Drupal book hierarchies

I'm just getting round to converting our static HTML website to Drupal. Our website is currently structured into sections, each section having a header, then a list of sub-sections below (for an example see http://www.eurosafeuk.co.uk/services/).
This ties in very nicely with Drupal's "book" module, but I need to customise the display of child pages; by default they're printed as an unordered list of page titles, whereas what I need is to output:
A teaser image for each page
The page title
The page summary
I've looked through the .tpl files, and found that the children are stored in a $tree variable (already HTML formatted). My question is: where do I start if I want to modify this? Does anyone know of a pre-existing module that would do it, or do I need to dig into the code?
Instead of using the Book module which is specifically for a book structure, you might want to look into modules that are made for your case. I haven't looked very well but the Node Hierarchy module might be useful for you. . Here is an excerpt from its project page:
... allows nodes to be children of other nodes creating a tree-like hierarchy of content. The module offers:
1-Click creation of hierarchical menus
Hierarchical breadcrumbs
Automatic hierarchical urls using Pathauto (and token module)
(eg: q=aboutus/history/beginning).
Automatic creation of hierarchical menus if desired.
Optional Views integration.
Optional Node Access integration.
If you want to theme nodes in specific sections in different ways, it's probably a good idea to make separate .tpl files for every section. The way you name those .tpl files makes them applicable to nodes in a certain section.
Get the devel module, and turn on theme developer. This will tell you the template or function which is used to build the HTML and what templates you can create to override it.

Resources