Jump to content

JimSee
 Share

Recommended Posts

Hello!

I've finally learned enough to be dangerous...or maybe I knew that much all along. ;) Anyway, I prepared a site to help us do some non-profit work...but...

Comment Dates: The directions with dates seem clear enough and I've read them and tried all the following

  • <?php echo date("D M j G:i:s T Y"); ?>
  • echo date("D M j G:i:s T Y");
  • date("D M j G:i:s T Y")
  • "D M j G:i:s T Y"
  • D M j G:i:s T Y

Yet, when I save the Comments field and refresh the page, I still get a relative date (such as "8 seconds ago.")

Can someone help (please)?

= = = = = =

Comments Render Array: Using the directions at Comments, I can safely use $content .=  $page->comment->render(array()); and my comments will show up. However, I get an error if I add something like the very first example $page->comment->render(array('headline' => '<h2>Read Comments</h2>',));

The error in this case was Parse Error: syntax error, unexpected ''headline'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' (line 11 of C:\0\www\pwlimit\site\templates\member.php)

I've tried a variety of things... Usually, I get an error with no explanation.

Can someone help (please)?

= = = = = =

Comments Email: When I check Allow Commenter Email Notifications, i don't get an email.

Can someone help (please)?

Thank you in advance for your help!

Especially, thank you for your patience!

 

Edited by JimSee
i forgot that i needed to check notify of replies.
Link to comment
Share on other sites

Thank you for responding fbg13! I've tried to give you enough the code and some more info. Thank you !!!

I added some notes to the code but here's one version:

<?php namespace ProcessWire;
// member.php template file
// has restricted access and comments
// Primary content is the page's body copy
$content = $page->body;
$content .=  $page->chair2program;
$content .=  "<div class=dialogue>";
/* Before, i used the comments.css "out of the box." Now, i have
* a class dialogue for my own purposes.
* HOWEVER, the website url does NOT show up either way.
*/
$content .=  $page->comment->renderAll();
/* The above works fine except for the problems with RELATIVE DATE
* and the WEBSITE not showing up.
* It also works fine with
* $content .=  $page->comment->render();
* $content .=  $page->comment->renderForm();
*
* BUT i get an error with the example shown
* and the other errors on https://processwire.com/api/fieldtypes/comments/
*/
$content .=  "</div>";
if($page->hasChildren) {
 $content .= renderNav($page->children);
}
 
The first picture shows the code that I changed and the resulting error. I also tried different things at https://processwire.com/api/fieldtypes/comments/ 
The second picture shows my difficulty with dating. You can also see that I checked "Use Website Field in Comment Form." It doesn't show up although the formatted stars show up. (For the css, I used comments.css  and also a slightly modified version of my own.
 
 

errorandcode.png

CommentsPageNoted.png

Link to comment
Share on other sites

@JimSee The date part is a bug with PW.

No idea about the error, works for me (copied your code and just replaced the comments field name). What pw, php versions are you using?

Is your server able to send emails? Ask your host if you don't know.

  • Like 2
Link to comment
Share on other sites

Thank you for your quick response, fbg13!
 
i'm using ProcessWire 3.0.42 both online and off. i'm using PHP Version 5.5.19 (on Wamp ZeroXI - 11.5.3) and 5.5 on GoDaddy.
 
It seems strange to me that things work fine with comment->renderAll(); and comment->render(array(); but things go haywire when i stick something inside the brackets for the array. {{{sigh}}}
 
I just tried a clean install (intermediate version) on Wamp and have the same results.
= = = =
Also, do you know why the website does not show up?
 
Thank again for your kind assistance, fbg13!
Link to comment
Share on other sites

4 hours ago, fbg13 said:

The date part is a bug with PW.

Is this a known bug that has been reported at GitHub? I couldn't find any report for it so have opened a new issue here.

@JimSee, until this is fixed in the core you can work around the date format issue by supplying a date format as part of the $options array when you render the comments list, e.g.

echo $page->comments->render(array(
    'headline' => '<h2>Read Comments</h2>',
    'dateFormat' => 'm/d/y g:ia',
    ));

 

 

24 minutes ago, JimSee said:

Also, do you know why the website does not show up?

The website is rendered as a link using the commenter's name as the link text:

2017-06-26_111415.png.d3c7f36883b6bcacb6da0abeb3d42ace.png

 

  • Like 2
Link to comment
Share on other sites

8 minutes ago, Robin S said:

Is this a known bug that has been reported at GitHub?

The option was hard coded to 'relative' instead of using the user set option. I submitted a pull request.

34 minutes ago, JimSee said:

I just tried a clean install (intermediate version) on Wamp and have the same results.

Did you do anything else beside adding the comment field?  It works for me on pw version 3.0.42 and php 5.5 on the intermediate profile. Make sure you don't have any typos in your code.

Also when sharing code use the code button <> and add the code that way.

  • Like 2
Link to comment
Share on other sites

Hello Robin S and hello again fbg13

After Robin S wrote The website is rendered as a link using the commenter's name as the link text, it's obvious...but I sure didn't see it. Thank you for that info!

Thank you for your help and for persevering, fbg13! You asked, "Did you do anything else beside adding the comment field?" No, I installed ONLY the comments field.

Then this code worked fine:

<?php namespace ProcessWire;

// basic-page.php template file 
// See README.txt for more information

// Primary content is the page's body copy
$content = $page->body; 

$content .= $page->comments->render(array());   
$content .= $page->comments->renderForm(array()); 

// If the page has children, then render navigation to them under the body.
// See the _func.php for the renderNav example function.
if($page->hasChildren) {
	$content .= renderNav($page->children);
}

// if the rootParent (section) page has more than 1 child, then render 
// section navigation in the sidebar
if($page->rootParent->hasChildren > 1) {
	$sidebar = renderNavTree($page->rootParent, 3) . $page->sidebar; 
}

I added the example inside the array and now the changed code throws the error below:

<?php namespace ProcessWire;

// basic-page.php template file 
// See README.txt for more information

// Primary content is the page's body copy
$content = $page->body; 

$content .= $page->comments->render(array(
    'headline' => '<h2>Read Comments</h2>',
    ));   
$content .= $page->comments->renderForm(array()); 

// If the page has children, then render navigation to them under the body.
// See the _func.php for the renderNav example function.
if($page->hasChildren) {
	$content .= renderNav($page->children);
}

// if the rootParent (section) page has more than 1 child, then render 
// section navigation in the sidebar
if($page->rootParent->hasChildren > 1) {
	$sidebar = renderNavTree($page->rootParent, 3) . $page->sidebar; 
}

Error log entry: Parse Error: syntax error, unexpected ''headline'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' (line 10 of C:\0\www\pwb\site\templates\basic-page.php)

Thank you again for your help, Robin S and fbg13 !

Link to comment
Share on other sites

@JimSee, that error can sometimes be caused by a weird invisible whitespace character in your code, particularly if you copy/pasted it from somewhere.

Try deleting this part...

$content .= $page->comments->render(array(
    'headline' => '<h2>Read Comments</h2>',
    ));

...and then typing it out again from scratch.

  • Like 2
Link to comment
Share on other sites

Side notes: If you're on PHP 5.5, you should be using square array notation. So instead of array(...), use [...]. I also recommend that you upgrade to a newer version of PHP. The oldest version with any kind of support at all is 5.6, and so check if you can upgrade to that or 7.0 or 7.1. For local development, might be better to use EasyPHP as you can switch between versions easily.

  • Like 1
Link to comment
Share on other sites

Thank you fbg13Robin S and Mike Rockett !

For now, the Comments work good enough with page->comments->renderAll(); Still, I do look forward to the date being fixed.

My last efforts were:

  1. Upgraded my Wamp so that i'm using PHP 7.
  2. Downloaded, unzipped and installed ProcessWire 3.0.62
  3. Added Comments but first saved the array stuff in Notepad to be sure that any strange spaces were avoided.
  4. When it failed, used page->comments->renderAll(); to be sure that I didn't have some other kind of problem.

Thank you again!

 

  • Like 1
Link to comment
Share on other sites

On ‎6‎/‎25‎/‎2017 at 8:50 PM, Robin S said:

@JimSee, that error can sometimes be caused by a weird invisible whitespace character in your code, particularly if you copy/pasted it from somewhere.

Try deleting this part...


$content .= $page->comments->render(array(
    'headline' => '<h2>Read Comments</h2>',
    ));

...and then typing it out again from scratch.

Thank you, thank you, thank you, Robin S !

After returning and starting from "scratch," I strongly suspect that the weird invisible whitespace was the culprit. With another clean install, I typed everything Very Carefully (rather than cutting & pasting). It worked! I love my custom dates...and comments.

Thank you again for your help and your patience,  fbg13Robin S and Mike Rockett !

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...