Hi,
Firstly let me state that I know I do things wrong so before we move to the error part let's clarify the rest. I've watched the videos and read the how-to' guides. Sadly I cannot just import views and cck because those are already done (using my own content type with different naming for CCK fields). But the renaming is not an issue. What I'm worried is whether the fields of "Slide text - Text on a slide (new text field)" and "Pager item text - Text of a pager_item (new text field)" are required for a working ddblock. I don't want those fields - just fields of Title ,Teaser text and image. I followed the docs as instructed apart from those fields that I didn't add. Yet I get a "warning: Invalid argument supplied for foreach() in .... ddblock-cycle-block-content-modest-grey30p.tpl.php on line 47" . I've seen the troubleshooting page for this and I fear the reason is the missing fields that exist in my template.php but don't exist as CCK fields. Is this correct?If yes , can I do something about it (exclude lines from the template.php)? I wanted to clarify this before posting template files and start the troubleshooting.Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ppblaauw’s picture

Status: Active » Postponed (maintainer needs more info)

You can use your own view and cck content type with the ddblock module.
When you do, you need to change the view-name and the field-names in the preprocess functions.

None of the fields are required.
The error message comes probably from that you did not rename the view or you don't have nodes yet.

If you don't use fields you can always exclude them form the template files, but not necessary.

The templates files, preprocess functions are just there as an example and they can give you a headstart to make your own layouts.

Hope this helps you further, please let me know.

When you still have issues, please attach your template.php file, the result of the drupal_set_message debug lines, a link to the Internet site or the page source etc.

Try to describe what you want to accomplish, what you did, what you expect and what is different, so I can help you better.

charos’s picture

Thanks for the fast reply! What I want to achieve comes close to what the "Linux Foundation" did with ddblock (justthe pager without the additional text-just the title). The view is renamed, about the renamed field-names , only the imagecache shall be chosen but this is done it the configurations of ddblock (admin/build/block/configure/ddblock/1). I have enough nodes to make a slideshow. It gets content through nodequeue. Surely things are messed up in the template file.So I am attaching it, along with my views export.
The error I get is : "none' (In green color) drupal_set_message('

' . var_export($vars['css'], true) . '

'); and

"warning: Invalid argument supplied for foreach() in /sites/all/themes/publisher/custom/modules/ddblock/ddblock-cycle-block-content-modest-grey30p.tpl.php on line 47." (in red color).
As you noticed , I disabled the ddblock_show_pager_debug_info($vars); and ddblock_show_content_debug_info($vars); because I got php errors when enabled (Fatal error: Call to undefined function ddblock_show_content_debug_info() )
I attach the template.php without the rest of the of the theming and paste only those related to ddblock. Hope those things will shed some light!

ppblaauw’s picture

You are using the preprocess functions for the new dev version of the dynamic display block module which are not compatible with RC6 of the module.

You need to download the Export_files_V1.4.zip which contains the preprocess function for RC6

Hope this helps you further, please let me know.

charos’s picture

FileSize
3.65 KB
5.73 KB
47.31 KB

Thank you! I tried the dev version before and forgeot to change the preprocess functions! I am getting there! I managed to get the slideshow starting which is a good sign! I used the modest-grey10p for a theme now to see how it behaves.As you can see, the pager is not shown and slide get oddly stopped. I attached a screenshot to show the problem I am facing now and hopefully you can help me even further! I include the later phptemplate related to ddblock along with the text from the debug display. Hope this will be enlightening! Thanks for all your attention!

charos’s picture

Ok , I think I will find a way out of this! Don't bother until I try few things (deal with the custom pager settings). Will let you know as soon as I figure things out.

charos’s picture

So, I managed to create a ddblock when a theme (like modest-grey10p) supports numbered pages! I am almost there to the perfect behavior I want! What I need is to add a custom pager with pager text of Node title. Is this possible?? I guess if I had the pager_item text field in the content type things would be easy. Now that I want the text of the pager to be the node title, I need to do some some serious editing! I really wonder if that is possible without php knowledge!

ppblaauw’s picture

The theme numbers have the following meaning:

10 - with number pager
20 - with previous/next pager
30 - with text pager
40 - with image pager
50 - with image/text pager
60 - with scrollable pager

For your text pager you can better start with modest-grey30p which has already a text pager.

In the preprocess function for the pager-items instead of using the pager-item field use the title.

This is a minimal change. (use $result->node_title instead of the pager-item field)

Hope this helps you further, please let me know.

charos’s picture

Thanks a lot for the numbering explaination! It works great with the $result->node_title in pager! I tried to do the same with the slide_text variable do display the teaser (since now the pager and slider show the same text - title) . But I can't make it. I tried to do the same thing as node_title but instead I used node_teaser (replace $slider_items[$key1]['slide_text'] = $result->node_data_field_pager_item_text_field_slide_text_value; with $result->node_teaser) . I am not sure whether this function exists :) . If you have any ideas I'd appreciate the tip. If not it's fine since you helped more than enough already and this is beyond the scope of module support - more of php for dummies! I really appreciate the time and effort you put to help me out!!

ppblaauw’s picture

In the debug info (result of the drupal_set_message line) you can see which field_names you have available for your slideshow.
The node teaser has the field name: node_revisions_teaser, so you need to use:

 $result->node_revisions_teaser

Hope this helps you further, please let me know.

charos’s picture

Status: Postponed (maintainer needs more info) » Fixed

Thanks a lot!! The ddblock works perfect now :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

slampy’s picture

Status: Closed (fixed) » Needs review

Sorry for reopening this issue, but the $result->node_revisions_teaser doesn't work for me quite as I expected.

In the news_items view I added the Teaser field and set to be trimmed for 5 characters, but it doesn't work. I also uncommented the debug info line, but it still doesn't show me my fields.

I would like to use the teaser trimmed for the slide_text variable.

Thanks!

airen2011’s picture

Status: Needs review » Postponed (maintainer needs more info)

You need to trim your field in the preprocess function.
Please attach the result of your debug lines, your template.php file and provide a link to the internet site, so I can help you better.

slampy’s picture

I would like to trim the teaser so it trims only words and puts a '...' after the trimmed string. And also strips the HTML tags.

Here is my template.php file:
function garland_preprocess_ddblock_cycle_block_content(&$vars) {
if ($vars['output_type'] == 'view_fields') {
$content = array();
// Add slider_items for the template
// If you use the devel module uncomment the following line to see the theme variables
// dsm($vars['settings']['view_name']);
// dsm($vars['content'][0]);
// If you don't use the devel module uncomment the following line to see the theme variables
drupal_set_message('

' . var_export($vars['settings']['view_name'], true) . '

');
drupal_set_message('

' . var_export($vars['content'][0], true) . '

');
if ($vars['settings']['view_name'] == 'news_items') {
if (!empty($vars['content'])) {
foreach ($vars['content'] as $key1 => $result) {
// add slide_image variable

if (isset($result->node_data_field_pager_item_text_field_image_fid)) {
// get image id
$fid = $result->node_data_field_pager_item_text_field_image_fid;
// get path to image
$filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid));
// use imagecache (imagecache, preset_name, file_path, alt, title, array of attributes)
if (module_exists('imagecache') && is_array(imagecache_presets()) && $vars['imgcache_slide'] <> ''){
$slider_items[$key1]['slide_image'] =
theme('imagecache',
$vars['imgcache_slide'],
$filepath,
check_plain($result->node_title));
}
else {
$slider_items[$key1]['slide_image'] =
'Only local images are allowed. '" alt="' . check_plain($result->node_title) .
'"/>';
}
}
// add slide_text variable
if (isset($result->node_revisions_teaser)) {
$slider_items[$key1]['slide_text'] = check_markup($result->node_revisions_teaser);
}
// add slide_title variable
if (isset($result->node_title)) {
$slider_items[$key1]['slide_title'] = check_plain($result->node_title);
}
// add slide_read_more variable and slide_node variable
if (isset($result->nid)) {
$slider_items[$key1]['slide_read_more'] = l('Read more...', 'node/' . $result->nid);
$slider_items[$key1]['slide_node'] = base_path() . 'node/' . $result->nid;
}
}
}
}
$vars['slider_items'] = $slider_items;
}
}
/**
* Override or insert variables into the ddblock_cycle_pager_content templates.
* Used to convert variables from view_fields to pager_items template variables
* Only used for custom pager items
*
* @param $vars
* An array of variables to pass to the theme template.
*
*/
function garland_preprocess_ddblock_cycle_pager_content(&$vars) {
if (($vars['output_type'] == 'view_fields') && ($vars['pager_settings']['pager'] == 'custom-pager')){
$content = array();
// Add pager_items for the template
// If you use the devel module uncomment the following lines to see the theme variables
// dsm($vars['pager_settings']['view_name']);
// dsm($vars['content'][0]);
// If you don't use the devel module uncomment the following lines to see the theme variables
// drupal_set_message('

' . var_export($vars['pager_settings'], true) . '

');
// drupal_set_message('

' . var_export($vars['content'][0], true) . '

');
if ($vars['pager_settings']['view_name'] == 'news_items') {
if (!empty($vars['content'])) {
foreach ($vars['content'] as $key1 => $result) {
// add pager_item_image variable
if (isset($result->node_data_field_pager_item_text_field_image_fid)) {
$fid = $result->node_data_field_pager_item_text_field_image_fid;
$filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid));
// use imagecache (imagecache, preset_name, file_path, alt, title, array of attributes)
if (module_exists('imagecache') &&
is_array(imagecache_presets()) &&
$vars['imgcache_pager_item'] <> ''){
$pager_items[$key1]['image'] =
theme('imagecache',
$vars['pager_settings']['imgcache_pager_item'],
$filepath,
check_plain($result->node_data_field_pager_item_text_field_pager_item_text_value));
}
else {
$pager_items[$key1]['image'] =
'Only local images are allowed. '" alt="' . check_plain($result->node_data_field_pager_item_text_field_pager_item_text_value) .
'"/>';
}
}
// add pager_item _text variable
if (isset($result->node_title)) {
$pager_items[$key1]['text'] = check_plain($result->node_title);
}
}
}
}
$vars['pager_items'] = $pager_items;
}
}

Here is my debug info:
*

'news_items'

*

stdClass::__set_state(array(
'nid' => '54',
'node_title' => 'Test title',
'node_revisions_teaser' => 'Test teaser',
'node_revisions_format' => '2',
'node_type' => 'story',
'node_vid' => '54',
'node_created' => '1256215538',
))

ppblaauw’s picture

It looks like your node_revisions_teaser field shows up in the debug line and you use it in your template, so the node teaser should show up as your slidetext.

--
I would like to trim the teaser so it trims only words and puts a '...' after the trimmed string. And also strips the HTML tags.

What code in the preprocess function did you try to get this functionality working and what was not working.

slampy’s picture

I have put these settings into the news_items view under the teaser field.

ppblaauw’s picture

Like said in #13 you need to use code to trim fields in the preprocess function.

slampy’s picture

Status: Postponed (maintainer needs more info) » Fixed

Thanks.

I used this function to trim the teaser: http://www.lullabot.com/articles/trim_a_string_to_a_given_word_count

ppblaauw’s picture

Status: Fixed » Postponed (maintainer needs more info)

Thanks for the link, you could also use the following code which is a copy of the code used in views:

Only the parameters are not used

        // add slide_text variable
        if (isset($result->node_revisions_teaser)) {
          // cut teaser on word boundary
          $value = drupal_substr($result->node_revisions_teaser, 0, 100);
          // cut  teaser further on word boundary
          if (preg_match("/(.*)\b.+/us", $value, $matches)) {
            $value = $matches[1];
          }
          // Remove scraps of HTML entities from the end of a strings
          $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));
          // add ellipses
          $value .= '...';
          //Scan input and make sure that all HTML tags are properly closed and nested.
          $value = _filter_htmlcorrector($value);
          $slider_items[$key1]['slide_text'] =  $value;
        }

The original code is in the function: function render_trim_text($value)
at line 450 of sites\all\modules\views\handlers\views_handler_field.inc

Hope this helps you further, please let me know.
(used the code, but did not test it much with different string)

slampy’s picture

Status: Postponed (maintainer needs more info) » Fixed

Thanks, this works great!

And because it counts the chars and not the words (like the Lullabot article) it is much more usefull.

slampy’s picture

Status: Fixed » Needs review

As I was checking HTML validation I realized, that it is better if we remove all HTML tags.

So I think this would work also:

// add slide_text variable
        if (isset($result->node_revisions_teaser)) {
          // remove all HTML tags
          $value = strip_tags($result->node_revisions_teaser);
          // cut teaser on word boundary
          $value = drupal_substr($value, 0, 100);
          // cut  teaser further on word boundary
          if (preg_match("/(.*)\b.+/us", $value, $matches)) {
            $value = $matches[1];
          }
          // add ellipses
          $value .= '...';

          $slider_items[$key1]['slide_text'] =  $value;
        }

But there is still one problem. If the teaser contains for example a '&' sign. How can I encode it to '&'?

ppblaauw’s picture

Status: Needs review » Postponed (maintainer needs more info)

#21

Code looks good to me and useful if you don't allow HTML. Thanks for posting.

If you only want to encode & to & you could use a string replace for this just before you add the ellipses.

Hope this helps you further, please let me know.

slampy’s picture

Is there a PHP or Drupal API function for making valid HTML chars?

Here is the code for the '&' replacement:

$value = str_replace('&','&amp;',$value);
ppblaauw’s picture

You could probably use htmlspecialchars() or htmlentities() which is are PHP functions.

$value = htmlspecialchars($value, ENT_QUOTES);

the translations performed are:

'&' (ampersand) becomes '&amp;'
'"' (double quote) becomes '&quot;' when ENT_NOQUOTES is not set.
''' (single quote) becomes '&#039;' only when ENT_QUOTES is set.
'<' (less than) becomes '&lt;'
'>' (greater than) becomes '&gt;'

If you require all HTML character entities to be translated, use htmlentities() instead.

$value = htmlentities($value);

Hope this helps you further, please let me know.

slampy’s picture

Status: Postponed (maintainer needs more info) » Fixed

Thanks! The code now not only works great but also provides valid HTML too.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.