By tce on
I'm using hook_page_alter to add to the content render array - just to add some additional markup. In a module, I have something similar to the following
<?php
$page['content']['system_main']['test'] = array(
'#theme' => 'item_list',
'#items' => array(
t('A string with & in it.'),
t('Another string with & in it'),
),
);
?>What is the best way to escape the & so it validates with W3C? I can do it this way using check_plain(), but it seems very untidy
<?php
$page['content']['system_main']['test'] = array(
'#theme' => 'item_list',
'#items' => array(
check_plain(t('A string with & in it.')),
check_plain(t('Another string with & in it')),
),
);
?>Am I missing something obvious?
Comments
I have no idea about PHP
But I know how to use Google and limit the search to drupal.org
(since the d.o search is worthless to me)
Google Search: site:drupal.org
https://www.google.com/webhp?q=site%3Adrupal.org+
Note 1: Do Not insert a blank-space after the colon (":") before the first letter of the domain name ("drupal.org").
Note 2: Type a blank-space following the plus-sign (+),
and add your keyword(s) &/or "keyword phrase"(s).
Wrap a multi-word keyword phrase in double-quotes ("... ... ... ")
to search for exact phrase matching in the search.
Sample Google search of d.o
Example using keyword(s): escaping ampersand php
https://www.google.com/search?q=site%3Adrupal.org+escaping+ampersand+php
===
All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *
Can anyone else actually add
Can anyone else actually add something helpful here, rather than a condescending link to Google?
To the last poster, do you just go through all Drupal forum posts and refer them to Google? I'm sorry but that just defeats the whole purpose of a forum.
Just to be clear, I couldn't find the answer from Google, but as you know "how to use Google", perhaps you can help me find it?
My dear friend:
I have no way of knowing your level of experience in these forums,
but given that no one had responded to your question after some days,
and assuming that you would had posted the [solved] version if you had,
I give you, as I do anyone who is in need, the best of what I know and have
right now, with the hope and desire that it will propel your forward to your dream.
Not one in five people know that if they were to use a Google search limited to only drupal.org
that if they then could not find their answer after using every poignant keyword in their query,
they could then feel fully confident that their answer is not to be found anywhere on this site.
And you, or they, whether of a shy disposition or not, could proceed to post with out hesitation
knowing full well that they have done thorough research in advance.
: o )
"All the best; intended."
-chris
All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *
The problem here is, for
The problem here is that those people who do know how to use Google properly are just plain offended by your answer. I'm not quite sure where you get your 1 in 5 statistic from, but I would have thought Drupal users would be fairly technically minded, especially those that post into the Module Development and Code Questions section of the forum, enough so as to know how to limit a Google search to only find results in the Drupal site.
I'm sorry, I just feel you are trying to be helpful without actually being helpful. You seem to start a lot of your post answers with
I think it would be more helpful to me if you used your vast searching knowledge to help me find that one post with the answer that you think is there, but I cannot find. I am merely pointing out I don't find your initial answer helpful at all, but rather condescending, and I am not the only person to have mentioned that. Apart from that, your help is appreciated.
You may find the below link helpful, for future posts ;)
http://lmgtfy.com/?q=site%3Adrupal.org
I do appreciate your input in all sincerity
- My use of "I don't know the answer, but..."
was intended to fore-warn an issue's creator;
but also to consistently 'flag' my comment
as 'the same 'ole, same 'ole'
for members who regularly peruse
as many forum issues as they can;
JayPan being a note-able example.
- 4/5 ..lol.. yeah that was out of my, um, ***.
Hat. Yeah. That's it. That was simply out from under my hat.
I must say, your link, http://lmgtfy.com/?q=site%3Adrupal.org,...
...that is platinum-gold to me. Seriously great.
A picture is worth a thousand words, and an animation/ video
is exponentially better still. That link I do cherish for future use.
- Everything else aside, you will kindly take note of the fact
that after a week and half of no replies to your post,
whether by coincidence or not I do not know,
but you did fairly quickly get a response
following the spirit of my intent to help you
as I have seen happen elsewhere on this site.
...though I do allow that I may occasionally
have more knowledgeable individuals following my posts
possibly with the intent of fathoming my spirit,
but more likely, to find sufficient cause to permanently ban me
from d.o.
: o )
Plus it is a 'bump' of your issue, which increases the chance
your old post will be seen; and you need not be concerned
about whether you ought to bump it yourself: my gift to you,
intended; not knowing whether you or any issue's creator
might be too shy to bump.
- I like your idea of my posting a relevant link to a page's issue--
a link that will take you to your solution.
In that regard, my thought is that a d.o search engine
can potentially be better than Google might be
given that a d.o search can filter by 'Date',
and therefore give you the most current discussions
of your issue.
But the process of doing a search at d.o
using multiple keywords or keyword-phrases
involves converting symbols to their URL equivalents--
as in search of the keyword "test" AND the keyword-phrase "keyword phrase"
involves entering into the d.o search field-box
%22test%22%2b%22keyword%20phrase%22or the use in the browser address-bar of
%2522test%2522%252b%2522keyword%2520phrase%2522...though that is the documentation handbook tutorial
of my present singular intent.
.
.
.
"All the best; intended."
- chris
All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *
Plus it is a 'bump' of your
I agree with you here, good point. My question got answered so you have been helpful, thank you.
You can just encode it
You can just encode it yourself right in your string:
print t('A string with an & in it')Or, you could run it through a string replace, only for the &:
print str_replace('&', '&', t('A string with an & in it'));Or you could even write a function that does this:
But really, check plain() is probably your best bet.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks for the reply. I was
Thanks for the reply. I was just curious what the best practice was, considering it's a render array. It would have been great if the render() function took care of this, but I guess there is probably a reason it doesn't that I'm not aware of. I'm happy to use check_plain() for each line where needed.
In your case, you are
In your case, you are responsible for escaping the text before putting it into the render array.
Contact me to contract me for D7 -> D10/11 migrations.