访问 Drupal-7-Theme-Form 中文本区域的内容
在我的自定义 theme-settings.php (zen-subtheme)中,我放置了以下代码,以在我的主题设置中获取带有文本格式的新文本区域:
<?php
function paper_form_system_theme_settings_alter(&$form, &$form_state) {
$form['paper_data'] = array(
'#type' => 'text_format',
'#title' => 'Put Text in here:',
'#rows' => 5,
'#resizable' => FALSE,
'#default_value' => 'xyz..',
'#format' => 'full_html'
);
}
写入来访问变量时
<?php
$pdata = theme_get_setting('paper_data');
echo $pdata;
?>
该表单工作正常,但是当我想通过在页面中 。 tpl.php,变量的内容没有呈现 - 而是打印单词“Array”...... 出了什么问题以及为什么? (如果我使用“textarea”作为类型而不是“text_format”,则所有内容都会呈现良好。)
in my custom theme-settings.php (zen-subtheme) i put following code to get a new textarea with textformat in my theme-settings:
<?php
function paper_form_system_theme_settings_alter(&$form, &$form_state) {
$form['paper_data'] = array(
'#type' => 'text_format',
'#title' => 'Put Text in here:',
'#rows' => 5,
'#resizable' => FALSE,
'#default_value' => 'xyz..',
'#format' => 'full_html'
);
}
the form is working perfektly, but when i want to access the variable by writing
<?php
$pdata = theme_get_setting('paper_data');
echo $pdata;
?>
in my page.tpl.php, the content of the variable is not rendered - instead the word "Array" is printed ...
What's wrong and why? (If i use 'textarea' as type instead of 'text_format', all is rendered well.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 Devel 模块的
dpm()
函数而不是echo()
来检查变量时,您就会明白。恕我直言,在没有 Devel 模块的情况下编写 Drupal 是愚蠢的。该问题很可能源于您对
text_format
类型的使用。如您所见,它保存了文本区域值以及关联的文本格式。使用此功能时,Drupal 以结构化形式返回数据,该形式根据格式类型而变化。dpm()
是你的朋友:)You will understand when you use something like the Devel module's
dpm()
function to check the variable rather thanecho()
. Coding Drupal without the Devel module is, IMHO, folly.The issue very likely stems from your use of the
text_format
type. As you can see, it saves both the textarea value as well as an associated text format. When this is used Drupal returns the data in structured form which varies depending on the type of format.dpm()
is your friend :)