Drupal 7 - Render fields in node template with different view mode - drupal-7

I have some fields for node. I hide contents and render fields separately as below
hide($content);
print render($content['field_01']);
print render($content['field_02']);
print render($content['field_03']);
print render($content['field_04']);
print render($content['field_05']);
I set different field formats in content type at Manage Display" like field_01 is an image and i set large image in Full Content and Thumb image in Teaser view mode. field_02 is a taxonomy reference field which i set Link in Full Content and Plain Text in Teaser view mode.
When i render fields in node template, all fields render as view mode "Full".
Now i want render all fields from default view mode "Full". Only I want to render field_01 & field_02 from Teaser view mode.

Put your code inside an if like this:
if($view_mode == 'full'){
[...]
}
elseif($view_mode == 'teaser'){
[...]
}

Related

Set focus on autocomplete field

I have a form that has some fields.
One field is autocomplete
.
The field is filled with information from a table
$f->addField('autocomplete','idfield','Field')->setValueList( $this->api->db->dsql()
->table('items')->field('id,name')->do_getAssoc() );
I'm trying to set the focus on that field when the page loads.
I have did this
On top of the page
$p->js()->_load('seteo_foco');
And then
seteo_foco.js
$(function(){
$("select:first").focus();
})
But this does not work.
Anybody can help ?
Thanks
Try TRUE like
$this->js(true)->_load('seteo_foco'); to load js file.
But in your js code your selector is incorrect. You need to specify you unique field. I'd use something like $form->getElement('field_name')->js(true)->focus(); on the page after the form has been initialized.

How can i have a link field in a content type display a default text when the field is empty

How can i have a link field in a content type display a default text when the field is empty.
For now i have a field as a link - and the link is set to have a static title. This Works fine.
But i'd like to display a default title if the field is empty with no link (but still rendered as a link/button).
It's not a view - so i can't use "rewrite output if empty".
I'm a newbee to drupal - so please help
This shows what I've got so far:
http://1fb72c32b5e90467b795f388746f7501b3ad8021.web9.temporaryurl.org/tmp/link2.PNG
When the link field is empty the button doesn't show. Instead of not showing when empty I'd like it to show someting like this as default:
http://1fb72c32b5e90467b795f388746f7501b3ad8021.web9.temporaryurl.org/tmp/link3.PNG (the button "Bestil på tlf...")
By simply using Link module, i don't think this is possible. But, follow below steps in your environment and i think you might achieve the goal:
Make custom template file for the page (i think, its product details page)
In that template file, check whether the link is empty or not
If link is not empty, show the link. If link is empty, show your custom HTML.

Add summary/teaser to Full content in drupal 7

I want to have both Summary and Body in full content view in Drupal 7 but I can't understand how it is possible.
You can edit theme template files to do that. just edit node.tpl.php or page.tpl.php in your theme.
For example get summary in node.tpl.php:
// Load node summary view
$node_view = node_view($node,'summary');
// Get the summary
$summary = $node_view['body'][0]['#markup'];
Or use views to create the content you want.

Issue with Nested List when data does not contain 'text' node

I want to render Nested list such that when I drill down back button shows name of parent node. I tried it but looks like if the JSON I am getting doesn't have node with name text, it won't work.
Here is the fiddle with local data (in my app I am using store to fetch this from service so I don't have control over name of nodes)
Please note back button where title is not populated when you go down the tree.
There is this displayField config of NestedList where you can specify which field to be used to set title and item text . By default it is set to text but you can specify it to be one of your model field.
Here's working fiddle based on your example. Only change is in config of NestedList at bottom.
But, if you are overriding getItemTextTpl or getTitleTextTpl, this config will be ignored.

Drupal 7 views Contextual filters with Page & Blocks

I have an issue and i'm hoping to get some advise.
I have a view created that show content based on the url:
eg:
domain.com/item/one
Shows fields for my node with the title one
domain.com/item/two
Shows fields for my node with the title two
etc etc.
The path for the PAGE in views is set to /item
What I'm having trouble with is I need to have a BLOCK (becuase I'm making it collapsable) show under that page with the specific URL show the body field for that node.
eg:
domain.com/item/three
Shows fields for my node with the title three as well as a block that show the body field for node three
I have set the Contextual filter for the PAGE to:
Content: Title
When the filter value is NOT in the URL
Show "Page not found"
Exception value : Empty (All removed)
Under More:
Case : Lowercase
Case in path : Lowercase
Transform spaces to dashes in URL : Checked
This works for the page but please let me know if I have set this up incorrectly.
I have set the same Contextual filter for BLOCK and it works in views preview but not on the page with the URL:
domain.com/item/three
Any advise on this would be greatly appreciated.

Resources