am trying to override the output of my page so I can add some PHP code, but the FiveStar module only give 2 options which is below or above Content. this is causing me problems as I'd like to include it in my HIDE technique, then I can choose where to place it.
e.g. (I hide all my output before rendering Content, then later I can render each as I choose, I cannot find the render for FiveStar Widget)
hide($content['comments']);
hide($content['links']);
hide($content['field_location']);
hide($content['body']);
hide($content['field_filename']);
hide($content['fivestar_widget']);
print render($content);
If any one can fill in the blanks for me would be awesome!
t.
If you place the widget after <?php print render($content) ?> you will have to use <?php hide($content['fivestar_widget_vote']); ?> before $content is rendered. Otherwise just use <?php print render($content['fivestar_widget_vote']); ?>. If it is before then the printed property will be set to true and it will only be rendered once.
Related
I have a file called page--advertsindex.tpl.php.. Now what i want to do is display that page inside the content region of page.tpl.php..
page--advertsindex.tpl.php contains the HTML which need's to be rendered in the content region of page.tpl but what it does currently when i navigate to my_drupal_site/advertsindex it only show's the html of page--advertsindex, not the page.tpl.php file and the page--advertsindex in the content region..
How can i do this? or is there a different way to achieve my goal?
Any page--<identifier>.tpl.php will be used instead of page.tpl.php for the url /identifier. That is by design and the entire purpose of this system. This can be extended for deeper paths too: page--foo-bar-baz.tpl.php for /foo/bar/baz.
If you want certain content to appear on /identifier, you have two options: Conditionally include the content or copy the content. What to choose depends on your situation.
Conditionally include: inside page.tpl.php:
<div class="footer">
<?php if (arg(0) == "advertsindex"): ?>
<?php print theme("advertsindex_disclaimer"); ?>
<?php endif; ?>
</div>
Overrides: introduce a page--advertsindex.tpl.php:
<div id="content">
<?php print $content ?>
</div>
When to choose what:
Only use conditional includes or conditional rendering when:
The content to be included or excluded is small and shared. Patterns like `[large 20+ line of frontpage HTML][normal HTML] are very bad.
The content to be included needs all sorts of fancy new variables pulled in. Patterns like are really bad. Drupals theme system is push (theme gets variables from modules) and never pull (theme requests parameters at modules).
In all other cases you'd use the overrides. And yes, that will include a lot of duplication, but that is by design and accepted as the default practice in Drupal. To avoid having to modify some HTML in 20+ files, "split" or "copy" them as late as possible.
A rule of thumb is that a conditional should be a few lines only and never require variables that are not available in the parent.
If advertsindex is would be one of your content type then you have to create node--advertsindex.tpl.php file instead of page--advertsindex.tpl.php. Or If you wont to display some content in the page.tpl.php page, then it is better to copy all code of page.tpl.php into YOUR-Custom_page.tpl.php and put your code inside the content section of YOUR-Custom_page.tpl.php.
I think it helps.
I have one specific template which drupal_set_message() does nothing on. The $messages are printed out in a header include which also exists on this template. I've triple checked that it's using the template I think it is, etc.
The only difference I can tell between this and any other page template I'm using is that this is a node-specific template. Specifically page-node-170.tpl.php.
Anyone have any ideas?
Make sure that the custom template (page-node-170.tpl.php) has the following lines somewhere visible:
<?php if ($show_messages && $messages): print $messages; endif; ?>
<?php print $help; ?>
Is it possible to use CCK to add a conditional to the image attach module form where unless I have selected an image to use for a content node, certain fields are not visible?
Currently I do not have any operations available for my image attach field in my content type definition where configure and remove are available for all other fields.
This would be really simple in your theme, e.g. node-foo.tpl.php for the content-type foo, that has a field "video"
<?php if(!empty($field_video[0]['view'])): ?>
<div class="block video">
<?php print $field_video[0]['view'] ?>
</div>
<?php print $field_some_other[0]['view'] ?>
<?php print $field_the_other_one[0]['view'] ?>
<?php endif; ?>
Some notes on style and best practices:
I prefer the if/endif in templates, others prefer the if() {}. Technically little difference, I think elseif; is more readable in HTML.
Technically it is not correct to simply print a value, but one should use drupal_render(). I personally still prefer print, because of its transparancy and simplicity. Drupal_render(), however, registers what it has "rendered" and allows you to drupal_render($node) at the end, to render all unrendered fields; very usefull if you decide to add fields later on, whithout having to change the entire template every time you do so. Drupal_render is not available in the tpl.php, but in the preprocessing: as sayd, a lot less transparent and slightly more complex.
Dont! Ever! print the $field_foo[0]['value'], always the ['view'] part: the first is unescaped and may (will!) contain XSS injections and the likes.
The strange nested array ($field_foo[0]['value']) is a result of the multiple-fields option in Drupal. A better way would be to always iterate over each field and never just render, hardcoded, the first ([0]) item. However, for reasons of readability, simplicity and transparancy, I prefer to hardcode the indexes in my template. Others (rightfully) disagree with me on this.
I tried to display body content with:
<?php print $node->content['body']['#value']; ?>
However, it doesn't display all body content, it just display first paragraph of body content, sometimes 2 paragraph if it is short :/
I need to print all body. how can I do that?
Thanks a lot! Appreciate helps!
The shortened body content hints on it being filled/rendered for 'teaser' view instead of 'full'. In what context do you issue this print statement?
EDIT: The node templates are usually used for both, teaser and full output, but the decision on what to use, as well as the population of the content entries in the node object happen outside of the node template files. Within the node template file, the variable $teaser will be TRUE, if the node is to be shown as a teaser.
So you need to check in what context your node template gets called, as you'll have to configure that context to render the node as 'full'. This could be in many places, depending on who is responsible to provide the nodes you want to theme, e.g. if the node template gets called from a view, you'll need to configure the view to use 'full page' output, if it comes from a module, you'll need to check with the module settings, etc...
In node.tpl.php try
<?php print $content ?>
However,
<?php print $node->content['body']['#value']; ?>
works for me as well.
To get control over your teaser length the master value is set with Post Settings.
(Length of trimmed posts)
To control this by node type try: http://drupal.org/project/teaserbytype
NOTE: Teasers are cached so you'll need to http://drupal.org/project/retease
However, if you want to just get it done in the node template you could run a node_load() and have everything... but that's not the best practice.
FYI: you can control what CCK fields show up in $content under Display Options.
PS: In teaser mode I often make use of truncate_utf8().
I can apply a custom theme to a certain content type in Drupal by copying the node.tpl.php file and placing the name of my content type right after the "node" in the file name and appending an hyphen. Ok, the new name is: node-page_two_columns_images.tpl.php.
But that won't give me much flexibility if I am not able to edit the way each of the fields of my content type are rendered. If you get the node.tpl.php file, here is the line I am interested in:
<?php print $content ?>
I need to edit the way the elements in $content are rendered. Why? Basically because the title of the page needs to go between two of these elements... more or less like this:
<div id="field-1-of-my-content-type">[stuff1]</div>
<h1><?php print $title ?></h1>
<div id="field-2-of-my-content-type">[stuff2]</div>
Is there a template file I can create to replace the elements in this $content variable or do I need to write my own specific function?
Thank you!
check out the content template module.
Instead of using $content, you can print out all the elements yourself, as they are available in the node template. That way you can arrange the title and CCK they way you want to.
Update:
The easiest way to theme a node with CCK fields is to use $field_[field_name]_rendered, it has the themed version of the CCK field. CCK creates that variable to make theming the node easier.