Change "from" to "for"

"Show a hidden or already printed element from later rendering." should read "Show a hidden or already printed element for later rendering."

CommentFileSizeAuthor
#14 930000-14.patch2.74 KBjhodgdon
#7 930000-7.patch2.84 KBjhodgdon
#1 930000.patch751 bytesbleen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bleen’s picture

Priority: Normal » Minor
Status: Active » Needs review
Issue tags: +Quick fix
FileSize
751 bytes
moshe weitzman’s picture

er, what does 'for later rendering' do for us? i say remove it.

kanani’s picture

Well it doesn't actually show the value, it just sets a print flag for when render is called. And if render has already been called once, that flag is ignored if you call render again, but that's a separate issue http://drupal.org/node/929802

jhodgdon’s picture

Status: Needs review » Needs work

How about "mark a ... for later rendering"?

And as long as we're fixing this function doc, "which" should always have a comma before it:

* Alternatively, render($element) could be used which automatically shows the
* element while rendering it.

and is that part clear at all? What do these two functions actually do anyway???

kanani’s picture

I don't think either of these functions actually work as intended. If you step through the code in debug, you can see the $element getting altered by the function, but once you call render, any subsequent adjustments to $element get ignored the next time you render($element).

See the bug report I filed in #3 above. Maybe i should file a separate documentation bug?

"Any nested elements are only rendered if they haven't been rendered before or if they have been re-enabled with show()." 

The second part "or if they have been re-enabled with show()." is inaccurate. Once render is called, show() and hide() have no affect on any subsequent calls to render(). The $element does get modified, but the output provided by render does not.
jhodgdon’s picture

OK, now you have me totally confused... I think this is all one documentation issue though.

Regarding #5 "Once render is called, show() and hide() have no affect on any subsequent calls to render()."... is this potentially because you didn't go high enough up in the render tree? (e.g. you said to show something, but it was already hidden higher up)? I guess I'm not understanding what is working, what isn't, and what you think should happen...

jhodgdon’s picture

Priority: Minor » Normal
Status: Needs work » Needs review
FileSize
2.84 KB

I did some more testing on http://drupal.org/node/929802#comment-3604502 and figured out what was going on, I think. Basically, show/hide only work before the first call to render(), because drupal_render() sets a #printed flag and never looks below the top level after the first call.

This needs to be documented on show() and hide(). Also, the render() documentation is wrong...

Here's a patch, which I think clarifies what happens in these functions.

jhodgdon’s picture

Title: Documentation problem with show » show(), hide(), and render() documentation is misleading
bleen’s picture

I think #7 is a tremendous improvement ... I still had to read it read it twice before I fully understood, but I dont have any suggestions on how to make it better. Any other thoughts

droplet’s picture

print render($content) first, then hide($content['comments']) = hide() has no effect
print hide($content['comments']) first, then print render($content), and then show($content['comments']) = show() has no effect
Is it ??

so when to use show() ??
print show() first if render element set to #printed flag = TRUE by default ?

my test, I have removed all codes in node.tpl.php and paste @jhodgdon codes.

(I don't know what is the default behavior, so commented what I saw)

print "<br />content without adulturation<br />";
print render($content);
// (content + comment)


hide($content['comments']);
print "<br />content with comments hidden<br />";
print render($content);
// (content + comment)

show($content['comments']);
print "<br />content with comments shown<br />";
print render($content);
// (content + comment)

print "<br />comments only<br />";
print render($content['comments']);
// comment only

print "<br />content again<br />";
print render($content);
// (content + comment)

print "<br />now return to your regular programming<br />";

"Remove the first print render($content) line to test that if you hide initially"


hide($content['comments']);
print "<br />content with comments hidden<br />";
print render($content);
//only content 

show($content['comments']);
print "<br />content with comments shown<br />";
print render($content);
// only content

print "<br />comments only<br />";
print render($content['comments']);
// only comment

print "<br />content again<br />";
print render($content);
// only content

print "<br />now return to your regular programming<br />";

** D7-dev up to date

jhodgdon’s picture

droplet: Please clarify - are you reviewing the patch in #7, and do you think it is correct/complete, or does it need work?

droplet’s picture

@jhodgdon,

Yes, reviewed the patch. I have read many time and don't really understand until testing examples code.
I'm not sure if I understand this 100% correctly, so draw a conclusion in my word above.

#7 is correct and complete if users understand what is elements/elements tree

"on an element low in the element tree"
=> xxx ..... lower in...xx
=>on an child element in the render element tree..

It's more clear to me.

** I'm not a native speaker

jhodgdon’s picture

OK, that is good feedback, thank you! I think we should change high/low terminology in the patch to use more parent/child terminology, as I think that is more standard.

jhodgdon’s picture

FileSize
2.74 KB

Here's a patch that hopefully changes the wording about show/hide to something that is clearer and only uses child/parent tree terminology.

bleen’s picture

This is much, much clearer. RTBC++ for me, but lets give it one more set of eyes...

droplet’s picture

Status: Needs review » Reviewed & tested by the community
Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Quick fix

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