我尝试在Joomla 3中构建一个简单的FAQ模块。
我在模块后端有4个字段。 "问题1&答案1" "问题2&答案2"。
我的php和Html是这样构建的:
<div id="accordion">
<h3 class="question"> <?php echo $params->get('question1'); ?></h3>
<div class="question">
<?php echo $params->get('answer1'); ?>
</div>
<h3 class="question"> <?php echo $params->get('question2'); ?></h3>
<div class="question">
<?php echo $params->get('answer2'); ?>
</div>
</div>
我想添加一些带有if语句的php,所以代码块只会渲染后端的文本字段,如果它们是从用户填写的那样:
(如果字段&#34;问题3&#34;有任何文字,请显示此代码)
<?php if ($this->params->get('question3')) : ?> //This is the line of code i do not know how to do.
<h3 class="question"> <?php echo $params->get('question2'); ?></h3>
<div class="question">
<?php echo $params->get('answer2'); ?>
</div>
</div>
<?php endif; ?>
这就是XML的样子:
<!-- Question 1 -->
<field
label="Question 1"
default=""
name="question1"
description="Fill in the question"
type="text"
size="60"
/>
<!-- End of Question 1 -->
<!-- Answer 1 -->
<field
label="Answer1"
default="Fill in the answer"
name="answer1"
description="Fill in the answer"
type="editor"
width="200"
height="100"
hide="readmore,pagebreak"
filter="safehtml"
size="260"
/>
<!-- End of Answer 1 -->
<field type="spacer" name="questionspacer2" label="<b>Question and Answer 2 1</b>" />
<!-- Question 2 -->
<field
label="Question 2"
default=""
name="question2"
description="Fill in the question"
type="text"
size="60"
/>
<!-- End of Question 2 -->
<!-- Answer 2 -->
<field
label="Answer2"
default=""
name="answer2"
description="Fill in the answer"
type="editor"
width="200"
height="100"
hide="readmore,pagebreak"
filter="safehtml"
size="260"
/>
<!-- End of Answer 2 -->
任何提示都会很棒!我已经整夜寻找解决方案。
答案 0 :(得分:1)
根据您设置参数的方式(如果未填充),您需要检查输出,如下所示:
$answer2 = $params->get('answer2'));
// (Applies if the not filled data returns NULL etc.)
if ( isset($answer2) ) { YOUR CODE }
// (Applies if the not filled data returns an empty string)
if ( !empty($answer2) ) { YOUR CODE }
未经测试,但应该可以使用;)
编辑:只是按照以下评论中所讨论的方式制作它应该是这样的:)